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:
5Solution:
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 题意: 当在社交网络上注册时,您总是被要求指定您的爱好,以便找到一些具有相同兴趣的潜在朋友.一个"社会群体"是一群拥有一些共同 ...
随机推荐
- How to show out three rows from the same databand On A4?
How to show out three rows from the same databand On A4? Quote Post by DoraHuang » Tue Mar 13, 2018 ...
- 数论---lcm和gcd
cd即最大公约数,lcm即最小公倍数. 首先给出a×b=gcd×lcm 证明:令gcd(a,b)=k,a=xk,b=yk,则a×b=xykk,而lcm=xyk,所以ab=gcd*lcm. 所以求lcm ...
- layer子窗口赋值给父窗口
子窗体赋值给父窗体: parent.$('#Receiver').val(typearr); //关闭子弹窗 var index = parent.layer.getFrameIndex(window ...
- 在php中定义常量时,const和define的区别?
使用const使得代码简单易读,const本身就是一个语言结构,而define是一个函数.另外const在编译时要比define快很多. 1.const用于类成员变量的定义,一经定义,不可修改.Def ...
- SQL语句优化方式--进阶篇
MYSQL性能 最大数据量 抛开数据量和并发数,谈性能都是扯淡(扯的最疼的那种).Mysql没有限制单表最大记录数,它取决与操作系统对文件大小的限制 文件系统 单文件大小限制 FAT32(采用32位二 ...
- TP框架的模板路径问题以及常用的模板常量的定义
在TP框架中,为了各个模块加载静态文件方便,往往是不需要按照默认的方式放置静态文件到/app/模块名/VIEWS/下面,而是在顶级目录下创建一个新的目录(比如说./tpl目录下),来存放静态文件 ...
- Python中sys模块
Python的sys模块提供访问解释器使用或维护的变量,和与解释器进行交互的函数.通俗来讲,sys模块负责程序与python解释器的交互,提供了一系列的函数和变量,用于操控python运行时的环境. ...
- 44-python基础-python3-字符串-常用字符串方法(二)-isalpha()-isalnum()-isdigit()-isspace()-istitle()
3-isX 字符串方法 序号 方法 条件 返回结果1 返回结果2 1 isalpha() 如果字符串只包含字母,并且非空; True False 2 isalnum() 如果字符串只包含字母和数字 ...
- PHP语言基础练习20191024
<style>*{font-size: 30px;}</style> //传地址 &<?phpfunction sum($a,&$b){ $c=$a+$ ...
- 用户Bug修补报告
用户Bug修补报告 虽然经过许多天的奋斗,我们的U-Help已经正式投入使用,不过在使用过程中遇到了大大小小的问题,我们通过努力修补了其中的相当一部分,以下是用户Bug修补报告. 7.31:发布bet ...