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
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2
Solution:
  排序而已,善于使用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的更多相关文章

  1. PAT甲级——A1141 PATRankingofInstitution【25】

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  2. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  3. PAT甲级1131. Subway Map

    PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任 ...

  4. PAT甲级1127. ZigZagging on a Tree

    PAT甲级1127. ZigZagging on a Tree 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二叉树可以通过给定的一对后序和顺序遍历序列来确定.这是一个简单的标准程序,可以按 ...

  5. PAT甲级1123. Is It a Complete AVL Tree

    PAT甲级1123. Is It a Complete AVL Tree 题意: 在AVL树中,任何节点的两个子树的高度最多有一个;如果在任何时候它们不同于一个,则重新平衡来恢复此属性.图1-4说明了 ...

  6. PAT甲级1119. Pre- and Post-order Traversals

    PAT甲级1119. Pre- and Post-order Traversals 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二进制树可以通过给定的一对后序和顺序遍历序列来确定,也可以通 ...

  7. PAT甲级1114. Family Property

    PAT甲级1114. Family Property 题意: 这一次,你应该帮我们收集家族财产的数据.鉴于每个人的家庭成员和他/她自己的名字的房地产(房产)信息,我们需要知道每个家庭的规模,以及他们的 ...

  8. PAT甲级1111. Online Map

    PAT甲级1111. Online Map 题意: 输入我们当前的位置和目的地,一个在线地图可以推荐几条路径.现在你的工作是向你的用户推荐两条路径:一条是最短的,另一条是最快的.确保任何请求存在路径. ...

  9. PAT甲级1107. Social Clusters

    PAT甲级1107. Social Clusters 题意: 当在社交网络上注册时,您总是被要求指定您的爱好,以便找到一些具有相同兴趣的潜在朋友.一个"社会群体"是一群拥有一些共同 ...

随机推荐

  1. python3反转列表的三种方式

    1.内建函数 reversed() li = [1,2,3,4,5,6] a = list(reversed(li)) print(a) 注意:reversed()函数返回的是一个迭代器,而不是一个L ...

  2. jQuery设置checkbox 为选中状态

    1设置第一个checkbox 为选中值$('input:checkbox:first').attr("checked",'checked');或者$('input:checkbox ...

  3. “希希敬敬对”队软件工程第九次作业-beta冲刺第三次随笔

    “希希敬敬对”队软件工程第九次作业-beta冲刺第三次随笔 队名:  “希希敬敬对” 龙江腾(队长) 201810775001 杨希                   201810812008 何敬 ...

  4. Spring Boot 2.x引入JS,CSS 失效问题

    我的SpringBoot版本是2.0,启动后发现页面奇丑无比: 看下目录结构: SpringBoot默认扫描Static文件夹下的文件,这里把CSS,JS以及图片文件都放在了asserts文件夹下. ...

  5. Groovy学习:第一章 用Groovy简化Java代码

    1. Groovy的安装 目前Groovy的最新版本为2.1.2版,下载地址为:http://groovy.codehaus.org/Download下载后解压groovy-binary-2.1.2. ...

  6. mac OS 安装 Homebrew及常用命令

    Homebrew  是由国外大神 Max Howell 开发的一款包管理工具,类似Debian的apt,他可以安装任何你想安装的东西. 安装方法 命令行输入 /usr/bin/ruby -e &quo ...

  7. AtCoder Beginner Contest 131 F - Must Be Rectangular!

    题意:给出二维平面的n个点坐标,定义一种操作:若恰好三个点能形成一个矩形(当然这个矩形会缺了一个点),那么就在图上添加这个缺的点,问在原图上最多能进行几次这样的操作. 解法:这题想了挺久没想到,一看题 ...

  8. Codeforces 1195E OpenStreetMap 单调队列套单调队列

    题意:给你一个n * m的矩阵,问所有的a * b的子矩阵的最小的元素的和是多少.题目给出了矩阵中的数的数据生成器. 思路:如果这个问题是1维的,即求所有区间的最小元素的和,用单调队列O(n)就可以做 ...

  9. Python Socket(未编辑)

    客户端 import socket 导入socket模块 client = socket.socket() 声明socket协议类型,同时生成socket连接对象 client.connect(('l ...

  10. eclipse设置tomcat部署目录地址

    参考: https://blog.csdn.net/lvyuan1234/article/details/53418818 右键,open 操作前提是所有项目移除,并且右键clean掉相关数据! 修改 ...