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. Spring Boot和Thymeleaf整合,结合JPA实现分页效果

    在项目里,我需要做一个Spring Boot结合Thymeleaf前端模版,结合JPA实现分页的演示效果.做的时候发现有些问题,也查了现有网上的不少文档,发现能全栈实现的不多,所以这里我就把我的做法, ...

  2. 基于Hi3559AV100 RFCN实现细节解析-(1)VGS初介绍

    下面随笔系列将对Hi3559AV100 RFCN实现细节进行解析,因为RFCN用到了VGS加框,因此本篇随笔将给出VGS视频图像子系统的具体说明,便于后面RFCN的细节实现说明. VGS 是视频图形子 ...

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

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

  4. 如何在 ASP.Net Core 中使用 MiniProfiler

    web应用程序的性能相信是大家普遍关心的一个问题,也相信大家有很多工具可用来分析应用程序的性能并能够找到其中的瓶颈,MiniProfiler 就是这个领域中的一款产品,它是一款简单的,功能强大的web ...

  5. 前端学习 node 快速入门 系列 —— 模块(module)

    其他章节请看: 前端学习 node 快速入门 系列 模块(module) 模块的导入 核心模块 在 初步认识 node 这篇文章中,我们在读文件的例子中用到了 require('fs'),在写最简单的 ...

  6. struts2.0中ognl栈的解析

    ongl详解: ValueStack是Struts2的一个接口,字面意义为值栈,OgnlValueStack是 ValueStack的实现类,客 户端发起一个请求,struts2架构会创建一个acti ...

  7. TensorFlow2.0使用方法

    TensorFlow2.0 1 使用技巧 更新到最新版本: pip install --upgrade tensorflow pip install --upgrade tensorflow-gpu ...

  8. android分析之Thread类

    线程与线程类要区分开来. 抽象来说,线程是CPU调度的最小单位,但是线程总要执行代码,这个代码就在线程类里说明(即Thread类).无论如何,Thread只是一个类,但其功能就是"启动一个线 ...

  9. 2019HDU多校第六场 6641 TDL

    一.题目 TDL 二.分析 题意就是找一个$n$满足题目中的公式,找不到就输出$-1$. 对于$${( f (n,m) - n )} \oplus {n} =k$$ 可以转换一下变成$( f (n,m ...

  10. 前端性能监控之performance

    如果我们想要对一个网页进行性能监控,那么使用window.performance是一个比较好的选择. 我们通过window.performance可以获取到用户访问一个页面的每个阶段的精确时间,从而对 ...