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 }

1025 PAT Ranking的更多相关文章

  1. 1025 PAT Ranking[排序][一般]

    1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...

  2. PAT 甲级 1025 PAT Ranking

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  3. 1025 PAT Ranking (25分)

    1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...

  4. PAT甲级——1025 PAT Ranking

    1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  5. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

  6. 【PAT】1025. PAT Ranking (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...

  7. 1025. PAT Ranking (25)

    题目如下: Programming Ability Test (PAT) is organized by the College of Computer Science and Technology ...

  8. 1025 PAT Ranking (25)(25 point(s))

    problem Programming Ability Test (PAT) is organized by the College of Computer Science and Technolog ...

  9. 1025 PAT Ranking 双重排序

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...

  10. PAT 甲级 1025.PAT Ranking C++/Java

      Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Z ...

随机推荐

  1. Python中的sklearn--KFold与StratifiedKFold

    KFold划分数据集的原理:根据n_split直接进行划分 StratifiedKFold划分数据集的原理:划分后的训练集和验证集中类别分布尽量和原数据集一样 #导入相关packages from s ...

  2. Markdown(1)介绍

    一.简介 ​ Markdown 是一种轻量级标记语言,通过简单的标记语法使纯文本内容具有一定格式,使用户可以用易读易写的纯文本格式编写文档. ​ Markdown 语言在 2004 由约翰·格鲁伯(英 ...

  3. 看完我的笔记不懂也会懂----Ajax

    Ajax(Asynchronous JavaScript And XML) - 本次学习所用到的插件 - XML - JSON - 关于AJAX - HTTP协议 - AJAX重点之XMLHttpRe ...

  4. js导出execl 兼容ie Chrome Firefox各种主流浏览器(js export execl)

    第一种导出table布局的表格 1 <html> 2 3 <head> 4 <meta charset="utf-8"> 5 <scrip ...

  5. 手把手教你Spring Boot2.x整合Elasticsearch(ES)

    文末会附上完整的代码包供大家下载参考,码字不易,如果对你有帮助请给个点赞和关注,谢谢! 如果只是想看java对于Elasticsearch的操作可以直接看第四大点 一.docker部署Elastics ...

  6. 打造综合性智慧城市之朔州开发区 3D 可视化

      前言 近几年,我国智慧城市建设步伐也不断加快,党中央和国务院也更加注重智慧园区的建设与发展,智慧园区建设与园区产业发展相结合,向着创新化.生态化发展,更加注重高新技术.绿色环保型等产业的发展,将管 ...

  7. (十三)数据库查询处理之QueryExecution(2)

    (十三)数据库查询处理之QueryExecution(2) 实验室这一周真的忙爆(虽然都是各种打杂的活)所以拖了很久终于在周末(摸鱼)把实验3做完了.同时准备把和查询这一块有关的博客补一下.然后就进入 ...

  8. cpu缓存和volatile

    目录 CPU缓存的由来 CPU缓存的概念 CPU缓存的意义 缓存一致性协议-MESI协议 Store Buffers Store Forwarding Memory Barriers Invalida ...

  9. FreeBSD 乃至开源界中的孔乙己 再论苦难哲学之一

    在许多狂热的FreeBSD 粉丝里,他们甚至不允许别人把FreeBSD写作freebsd,要和你强调,F和BSD都是大写的.还说这是什么尊重之类的东西.大抵和孔乙己的茴香豆的茴的有四种写法一样吧:&q ...

  10. ProBuilder快速原型开发技术 ---模型精细化操作

    前面我们讲解了很多ProBuilder功能,但是对于制作一款复杂的模型来说,还远远不够.需要更多的对于模型细节的处理,这就是本篇文章要讲解的"模型精细化操作"技术. 关于PB对于模 ...