Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive number N (≤), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

Output Specification:

For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

registration_number final_rank location_number local_rank
 

The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

Sample Input:

2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85
 

Sample Output:

9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4

题意:

  给出每个考生的成绩,求出其在考场中的排名和总排名。

思路:

  模拟 + 排序

Code:

 1 #include <bits/stdc++.h>
2
3 using namespace std;
4
5 struct Node {
6 string registration_number;
7 int final_rank;
8 int location_number;
9 int local_rank;
10 int grade;
11 };
12
13 bool cmp(Node a, Node b) {
14 if (a.grade == b.grade)
15 return a.registration_number < b.registration_number;
16 return a.grade > b.grade;
17 }
18
19 int main() {
20 int n, k;
21 cin >> n;
22 string registration_number;
23 int grade;
24 vector<Node> testees;
25 for (int i = 1; i <= n; ++i) {
26 cin >> k;
27 vector<Node> temp(k);
28 for (int j = 0; j < k; ++j) {
29 cin >> temp[j].registration_number >> temp[j].grade;
30 temp[j].location_number = i;
31 }
32 sort(temp.begin(), temp.end(), cmp);
33 int local_rank = 1;
34 temp[0].local_rank = 1;
35 testees.push_back(temp[0]);
36 for (int j = 1; j < k; ++j) {
37 local_rank++;
38 if (temp[j].grade != temp[j - 1].grade)
39 temp[j].local_rank = local_rank;
40 else
41 temp[j].local_rank = temp[j - 1].local_rank;
42 testees.push_back(temp[j]);
43 }
44 }
45 sort(testees.begin(), testees.end(), cmp);
46 int final_rank = 1;
47 testees[0].final_rank = 1;
48 for (int i = 1; i < testees.size(); ++i) {
49 final_rank++;
50 if (testees[i].grade != testees[i - 1].grade)
51 testees[i].final_rank = final_rank;
52 else
53 testees[i].final_rank = testees[i - 1].final_rank;
54 }
55 cout << testees.size() << endl;
56 for (int i = 0; i < testees.size(); ++i) {
57 cout << testees[i].registration_number << " " << testees[i].final_rank
58 << " " << testees[i].location_number << " "
59 << testees[i].local_rank << endl;
60 }
61 return 0;
62 }

最新文章

  1. 关于xml加载提示: Error on line 1 of document : 前言中不允许有内容
  2. 小书翻译完成,分享啦--《用Python操作大数据[MapReduceHadoop和Spark]》
  3. Android高手速成--第一部分 个性化控件(View)
  4. linux下MySQL安装及设置
  5. Android发展演变与开发环境搭建
  6. 实验9:Problem G: 克隆人来了!
  7. GIt 从入门到放弃
  8. JS 操作 radio input(cc问卷管理)
  9. [转]&quot;Windows Phone 7程序设计”完全版电子书可以免费下载了
  10. MySQL的SQL_CALC_FOUND_ROWS真的很慢么?
  11. 为什么不能在子类或外部发布C#事件
  12. python之路第二篇(基础篇)
  13. HTML5能否会成为Web技术的核心?
  14. 出现明明SQL语句没问题,但是却无法通过代码查询到结果的问题。
  15. [ 9.28 ]CF每日一题系列—— 940A规律构造
  16. 机器学习、NLP、Python和Math最好的150余个教程(建议收藏)
  17. 微信小程序 - cb回调(typeof cb == &quot;function&quot; &amp;&amp; cb(obj);)
  18. Linux清理Buffer/Cache内存空间让系统变流畅
  19. 使用 urllib 进行身份验证
  20. WPF 自定义ScrollViwer

热门文章

  1. Go的指针
  2. 你要是还学不会,请提刀来见 Typora+PicGo+Gitee + node.js 打造个人高效稳定优雅图床
  3. LeetCode392. 判断子序列
  4. HDOJ-1029(简单dp或者排序)
  5. 使用jsoup十分钟内掌握爬虫技术
  6. SpringMVC执行流程及源码分析
  7. SQL 性能起飞了!
  8. 一个mac软件合集的网站
  9. django框架如何解决跨域问题
  10. WPF 应用 - 使用 Properties.Settings 保存客户端密码