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 ;
}

最新文章

  1. jQuery focus、blur事件 添加、删除类名
  2. [2015hdu多校联赛补题]hdu5371 Hotaru&#39;s problem
  3. mypc---------------&gt;lspci,lsusb,meminfo cpuinfo ioports filesystems interrupts mounts net partitions pagetypeinfo slabinfo timer_list uptime version zoneinfo 等配置信息
  4. 庭审精彩语录整理 z
  5. A few things to remember while coding in Python.
  6. listview禁止双击一条之后选中复选框按钮的方法
  7. 回首Java(始)
  8. mysql 高效分页控件及c#调用实例
  9. [Angular Tutorial] 8 - Templating Links &amp; Images
  10. angularJS 与angujs-sku实现购物车组合查询
  11. Protocol Buffers(2):编码与解码
  12. Canvas 获得键盘焦点的方法
  13. NodeJS NPM 镜像使用方法
  14. Linux中DHCP服务器的简单配置
  15. 关键字new与malloc函数
  16. CSS多行文本垂直居中
  17. TextView展示富文本时emoj或图片和文字不对齐的解决方案
  18. 除去a标签target=&quot;_blank&quot;的方法
  19. Android 模拟器下载、编译及调试
  20. 改变element-ui滚动条设置,

热门文章

  1. c++primer,自定义一个复数类
  2. ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  3. python学习第二天--字符串及格式化输出
  4. python isinstance()函数和type()函数
  5. CTU Open 2018 Lighting /// 组合数递推 二进制
  6. C#实体类get和set的作用
  7. 使用await写异步优化代码
  8. 2018-5-26-Latex-去掉行号
  9. 不修改源代码,动态注入Java代码的方法(转)
  10. day13 python生成器函数 推导式 生成器