1025 PAT Ranking
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的更多相关文章
- 1025 PAT Ranking[排序][一般]
1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...
- PAT 甲级 1025 PAT Ranking
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- 1025 PAT Ranking (25分)
1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...
- PAT甲级——1025 PAT Ranking
1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...
- PAT甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...
- 【PAT】1025. PAT Ranking (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...
- 1025. PAT Ranking (25)
题目如下: Programming Ability Test (PAT) is organized by the College of Computer Science and Technology ...
- 1025 PAT Ranking (25)(25 point(s))
problem Programming Ability Test (PAT) is organized by the College of Computer Science and Technolog ...
- 1025 PAT Ranking 双重排序
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...
- PAT 甲级 1025.PAT Ranking C++/Java
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Z ...
随机推荐
- MySQL学习笔记(六)
好耶,七天课程的最后一天!我当然还没精通了,,,之后可能是多练习题目然后再学学其他的东西吧.mysql新的知识点也会在后面补充的. 一.杂七杂八补充 1. 当多个函数共用同样的参数时,可以转变成类进行 ...
- 查看手机CPU每个APP利用率
adb shell top -m 5
- 第39天学习打卡(UDP多线程在线咨询 URL)
UDP多线程在线咨询 package com.kuang.chat; import java.io.BufferedReader; import java.io.InputStreamReade ...
- 03.从0实现一个JVM语言系列之语法分析器-Parser-03月01日更新
从0实现JVM语言之语法分析器-Parser 相较于之前有较大更新, 老朋友们可以复盘或者针对bug留言, 我会看到之后答复您! 源码github仓库, 如果这个系列文章对你有帮助, 希望获得你的一个 ...
- POJ-1751(kruskal算法)
Highways POJ-1751 注意这里的样例答案也是对的,只是输出顺序改变,但是这也没关系,因为题目加了特殊判断. #include<iostream> #include<cs ...
- CTF-杂项笔记
01 赛题解答 (1)目标:了解modbus协议 (2)解题: 密文:666C61677B4533334237464438413342383431434139363939454 ...
- vs - 调试的技巧
在自助和局部变量窗口中固定属性 https://docs.microsoft.com/zh-cn/visualstudio/debugger/autos-and-locals-windows?view ...
- vue 倒计时 iOS无效
vue实现的倒计时在苹果手机上无效,原因是因为后台返回的时间格式是'2019-1-29 17:13:04',而苹果手机只能解析这种时间格式'YYYY/MM/DD HH:mm:ss',修改后测试成功的代 ...
- 微服务分布式事务之LCN、TCC
在亿级流量架构之分布式事务解决方案对比中, 已经简单阐明了从本机事务到分布式事务的演变过程, 文章的最后简单说明了TCC事务, 这儿将会深入了解TCC事务是原理, 以及理论支持, 最后会用Demo举例 ...
- P2260 [清华集训2012]模积和 【整除分块】
一.题目 P2260 [清华集训2012]模积和 二.分析 参考文章:click here 具体的公式推导可以看参考文章.博主的证明很详细. 自己在写的时候问题不在公式推导,公式还是能够比较顺利的推导 ...