PAT甲级——A1141 PATRankingofInstitution
After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (≤), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:
ID Score School
where ID
is a string of 6 characters with the first one representing the test level: B
stands for the basic level, A
the advanced level and T
the top level; Score
is an integer in [0, 100]; and School
is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that ID
is unique for each testee.
Output Specification:
For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:
Rank School TWS Ns
where Rank
is the rank (start from 1) of the institution; School
is the institution code (all in lower case); ; TWS
is the total weighted score which is defined to be the integer part of ScoreB/1.5 + ScoreA + ScoreT*1.5
, where ScoreX
is the total score of the testees belong to this institution on level X
; and Ns
is the total number of testees who belong to this institution.
The institutions are ranked according to their TWS
. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns
. If there is still a tie, they shall be printed in alphabetical order of their codes.
Sample Input:
10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu
Sample Output:
5
Solution:
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2
排序而已,善于使用unordermap!
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct Node
{
string id, school;
double tws;//切记,一定是double,每次PAT就是在这里下套
int score, nums, rank;
};
int main()
{
int n;
cin >> n;
vector<Node>v(n);
unordered_map<string, vector<int>>map;//记录相同学校的是哪些人
for (int i = ; i < n; ++i)
{
string name, school;
int score;
cin >> name >> score >> school;
for (int j = ; j < school.size(); ++j)
school[j] = tolower(school[j]);
v[i] = { name,school,0.0,score,, };
map[school].push_back(i);
}
vector<Node>res;
for (auto ptr = map.begin(); ptr != map.end(); ++ptr)
{
vector<int>p = ptr->second;
res.push_back({ "", v[p[]].school, 0.0, , (int)p.size(), });//将相同学校的分数相加
for (auto a : p)
{
if (v[a].id[] == 'A')
res.back().tws += v[a].score;
else if (v[a].id[] == 'B')
res.back().tws += v[a].score / 1.5;
else
res.back().tws += v[a].score * 1.5;
}
}
sort(res.begin(), res.end(), [](Node a, Node b) {//排名
if ((int(a.tws)) == (int(b.tws)) && a.nums == b.nums)
return a.school < b.school;
else if ((int(a.tws)) == (int(b.tws)))
return a.nums < b.nums;
else
return a.tws > b.tws;
});
cout << res.size() << endl;
for (int i = ; i < res.size(); ++i)
{
if (i > && ((int)res[i].tws) == ((int)res[i-].tws))
res[i].rank = res[i - ].rank;
else
res[i].rank = i + ;
cout << res[i].rank << " " << res[i].school << " " << (int)res[i].tws << " " << res[i].nums << endl;
}
return ;
}
PAT甲级——A1141 PATRankingofInstitution的更多相关文章
- PAT甲级——A1141 PATRankingofInstitution【25】
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级1131. Subway Map
PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任 ...
- PAT甲级1127. ZigZagging on a Tree
PAT甲级1127. ZigZagging on a Tree 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二叉树可以通过给定的一对后序和顺序遍历序列来确定.这是一个简单的标准程序,可以按 ...
- PAT甲级1123. Is It a Complete AVL Tree
PAT甲级1123. Is It a Complete AVL Tree 题意: 在AVL树中,任何节点的两个子树的高度最多有一个;如果在任何时候它们不同于一个,则重新平衡来恢复此属性.图1-4说明了 ...
- PAT甲级1119. Pre- and Post-order Traversals
PAT甲级1119. Pre- and Post-order Traversals 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二进制树可以通过给定的一对后序和顺序遍历序列来确定,也可以通 ...
- PAT甲级1114. Family Property
PAT甲级1114. Family Property 题意: 这一次,你应该帮我们收集家族财产的数据.鉴于每个人的家庭成员和他/她自己的名字的房地产(房产)信息,我们需要知道每个家庭的规模,以及他们的 ...
- PAT甲级1111. Online Map
PAT甲级1111. Online Map 题意: 输入我们当前的位置和目的地,一个在线地图可以推荐几条路径.现在你的工作是向你的用户推荐两条路径:一条是最短的,另一条是最快的.确保任何请求存在路径. ...
- PAT甲级1107. Social Clusters
PAT甲级1107. Social Clusters 题意: 当在社交网络上注册时,您总是被要求指定您的爱好,以便找到一些具有相同兴趣的潜在朋友.一个"社会群体"是一群拥有一些共同 ...
随机推荐
- Ajax的那点事
Ajax中什么是同步.异步? 同步:就是用户填写完信息之后,全部提交给服务器,等待服务器的回应,是一次性全部的. 异步:当用户填写完一条信息之后,这条信息会自动向服务器提交,然后服务器响应客户端,在此 ...
- Ubuntu18.10 编译libevent出现错误: creating symbolic link XXXXXX : Operation not supported
今天在VirtualBox虚拟机下的Ubuntu18.10编译libevent源代码时,按照github中使用cmake方式: $ mkdir build && cd build $ ...
- 转 linux 服务器内存占用统计
linux 服务器内存占用统计 原文: https://www.cnblogs.com/eaglediao/p/6641811.html 当前内存占用率的计算,是根据top命令显示的Mem.used ...
- C#socket客户端自己输入消息发送到服务端通信实现通信
一,服务端代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...
- js常用扩展方法
在日常的开发过程中,经常会碰到javaScript原生对象方法不够用的情况,所以经常会对javaScript原生方法进行扩展.下面就是在实际工作时,经常使用的一些方法,做一下记录,有需要的可以拿去. ...
- Ubuntu18.04安装Tensorflow1.14GPU
软件要求 必须在系统中安装以下 NVIDIA® 软件: https://www.pytorials.com/how-to-install-tensorflow-gpu-with-cuda-10-0-f ...
- eclipse里部署struts2
Struts2是一个比较出色的基于MVC设计模式的框架,是由Struts1和WebWork发展而来的,性能也比较稳定,现在是Apache软件基金会的一个项目,下面就来配置Struts2进行初始化的开发 ...
- React 组件嵌套 父子关系
代码实例; <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset=" ...
- html5中的选择器
1.html5中的属性选择器 <body> <style type=text/css> <!--1>完全匹配选择器--> [id=test]{ color:r ...
- C语言——杂实例
#include <stdio.h> #include <stdlib.h> #include <string.h> void f (int **p); void ...