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 ...
随机推荐
- Java网络编程UDP通信原理
前言 继续今天我们的Java网络编程--TCP和UDP通信 一.TCP和UDP概述 传输层通常以TCP和UDP协议来控制端点与端点的通信 TCP UDP 协议名称 传输控制协议 用户数据包协议 是 ...
- nacos服务注册之服务器端Distro
一致性协议算法Distro阿里自己的创的算法吧,网上能找到的资料很少.Distro用于处理ephemeral类型数据 Distro协议算法看代码大体流程是: nacos启动首先从其他远程节点同步全部数 ...
- NPOI 在指定单元格导入导出图片
NPOI 在指定单元格导入导出图片 Intro 我维护了一个 NPOI 的扩展,主要用来导入导出 Excel 数据,最近有网友提出了导入 Excel 的时候解析图片的需求,于是就有了本文的探索 导入E ...
- Java 程序员每天都在做什么?
作为一名 在大.中.小微企业都待过 的 Java 开发者,今天和大家分享下自己在不同公司的工作日常和收获.包括一些个人积累的工作提升经验,以及一些 Java 学习的方法和资源. 先从我的第一份 Jav ...
- [个人总结]pytorch中用checkpoint设置恢复,在恢复后的acc上升
原因是因为checkpoint设置好的确是保存了相关字段.但是其中设置的train_dataset却已经走过了epoch轮,当你再继续训练时候,train_dataset是从第一个load_data开 ...
- threejs 基础概要
threejs 基础概要 点击查看官方文档 下面是翻译的内容(稍作修改) 先了解一下Three.js应用程序的结构.Three.js应用程序需要创建一堆对象并将它们连接在一起.下图表示一个小three ...
- 14. vue源码入口+项目结构分析
一. vue源码 我们安装好vue以后, 如何了解vue的的代码结构, 从哪里下手呢? 1.1. vue源码入口 vue的入口是package.json 来分别看看是什么含义 dependences: ...
- Windows-Redis占用C盘系统空间
发现redis在电脑死机蓝屏的情况下,就是非正常退出redis会导致redis的缓存文件不会回收,占用系统空间, 下次在启动的时候,会再次创建一个10G多的缓存文件,极度占用磁盘空间. 现说明解决办法 ...
- JS利用cookie记录当前位置实现刷新页面后还可以保持菜单栏的展开或闭合
代码如下,重点是JS部分的代码(部分样式引用的是Bootstrapt中的): <style> .sidebar-menu .special{ font-size: 16px; marg ...
- JVM之调优及常见场景分析
JVM调优 GC调优是最后要做的工作,GC调优的目的可以总结为下面两点: 减少对象晋升到老年代的数量 减少FullGC的执行时间 通过监控排查问题及验证优化结果,可以分为: 命令监控:jps.jinf ...