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:

  1. 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:

  1. 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:

  1. 10
  2. A57908 85 Au
  3. B57908 54 LanX
  4. A37487 60 au
  5. T28374 67 CMU
  6. T32486 24 hypu
  7. A66734 92 cmu
  8. B76378 71 AU
  9. A47780 45 lanx
  10. A72809 100 pku
  11. A03274 45 hypu

Sample Output:

  1. 5
  2. 1 cmu 192 2
  3. 1 au 192 3
  4. 3 pku 100 1
  5. 4 hypu 81 2
  6. 4 lanx 81 2
  7.  
  8. Solution:
      排序而已,善于使用unordermap!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <unordered_map>
  5. #include <algorithm>
  6. using namespace std;
  7. struct Node
  8. {
  9. string id, school;
  10. double tws;//切记,一定是double,每次PAT就是在这里下套
  11. int score, nums, rank;
  12. };
  13. int main()
  14. {
  15. int n;
  16. cin >> n;
  17. vector<Node>v(n);
  18. unordered_map<string, vector<int>>map;//记录相同学校的是哪些人
  19. for (int i = ; i < n; ++i)
  20. {
  21. string name, school;
  22. int score;
  23. cin >> name >> score >> school;
  24. for (int j = ; j < school.size(); ++j)
  25. school[j] = tolower(school[j]);
  26. v[i] = { name,school,0.0,score,, };
  27. map[school].push_back(i);
  28. }
  29. vector<Node>res;
  30. for (auto ptr = map.begin(); ptr != map.end(); ++ptr)
  31. {
  32. vector<int>p = ptr->second;
  33. res.push_back({ "", v[p[]].school, 0.0, , (int)p.size(), });//将相同学校的分数相加
  34. for (auto a : p)
  35. {
  36. if (v[a].id[] == 'A')
  37. res.back().tws += v[a].score;
  38. else if (v[a].id[] == 'B')
  39. res.back().tws += v[a].score / 1.5;
  40. else
  41. res.back().tws += v[a].score * 1.5;
  42. }
  43. }
  44. sort(res.begin(), res.end(), [](Node a, Node b) {//排名
  45. if ((int(a.tws)) == (int(b.tws)) && a.nums == b.nums)
  46. return a.school < b.school;
  47. else if ((int(a.tws)) == (int(b.tws)))
  48. return a.nums < b.nums;
  49. else
  50. return a.tws > b.tws;
  51. });
  52. cout << res.size() << endl;
  53. for (int i = ; i < res.size(); ++i)
  54. {
  55. if (i > && ((int)res[i].tws) == ((int)res[i-].tws))
  56. res[i].rank = res[i - ].rank;
  57. else
  58. res[i].rank = i + ;
  59. cout << res[i].rank << " " << res[i].school << " " << (int)res[i].tws << " " << res[i].nums << endl;
  60. }
  61. return ;
  62. }

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. chromedriver安装报错

     解决方法:   可以使用 npm init -f命令生成package.json,package.json中缺少的字段可以参照模板 package.json进行填充,package.json中的字段 ...

  2. 我的WordPress站点

    读取VDI文件 SSL和TLS Windows下使用vim的最佳方案:Sublime gdb用法 VMware的Guest与Host进行通信的三种方式 加密与解密 漫谈保护模式 processing学 ...

  3. VC++实现窗口置顶

    最近在跟着Visual C++网络编程开发与实战视频教程做HttpSourceViewer这个MFC项目时,可以看我Github上的项目HttpSourceViewer,目前基本实现了所有功能,就是关 ...

  4. flink-training-course

    目录 flink-training-course 大数据领域顶级盛会 Flink Forward Asia 2019 详情

  5. CopyOnWriteArrayList(复制数组 去实现)

    一.Vector和SynchronizedList 1.1回顾线程安全的Vector和SynchronizedList 我们知道ArrayList是用于替代Vector的,Vector是线程安全的容器 ...

  6. c#静态变量和非静态变量的区别

    静态变量的类型说明符是static.静态变量当然是属于静态存储方式,但是属于静态存储方式的量不一定就是静态变量,例如外部变量虽属于静态存储方式,但不一定是静态变量,必须由 static加以定义后才能成 ...

  7. shell位置参数的遍历

  8. sleep - 延迟指定数量的时间

    总览 (SYNOPSIS) sleep [OPTION]... NUMBER[SUFFIX] 描述 (DESCRIPTION) 暂停 NUMBER 秒. SUFFIX 如果 是 s, 指 暂停 的 秒 ...

  9. 深度学习之Tensorflow 工程化项目实战 配套资源

    https://www.aianaconda.com/index/CodeProject

  10. IPv6 关于路由器配置静态IPv6路由的命令

    今天在学习路由器配置ipv6 的时候遇到了一点疑惑 一条命令为:ipv6 route FE80:0202::/32 serail 0/1 201 一条命令为:ipv6 route FE80:0202: ...