当前位置:网站首页>1025 PAT Ranking
1025 PAT Ranking
2022-06-27 19:50:00 【Brosto_ Cloud】
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 (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤300), 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#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct Stu {
string id;
int score;
int frank;
int lrank;
int lonum;
} a[50000];
bool cmp(Stu s1, Stu s2) {
return s1.score == s2.score ? s1.id < s2.id : s1.score > s2.score;
}
int main() {
int n, k, total = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> k;
for (int j = total + 1; j <= k + total; j++) {
cin >> a[j].id >> a[j].score;
a[j].lonum = i;
}
sort(a + total + 1, a + total + k + 1, cmp);
int t = 2;
a[total + 1].lrank = 1;
for (int j = total + 2; j <= k + total; j++) {
if (a[j].score == a[j - 1].score) {
a[j].lrank = a[j - 1].lrank;
} else {
a[j].lrank = t;
}
t++;
}
total += k;
}
sort(a + 1, a + total + 1, cmp);
int t = 2;
a[1].frank = 1;
for (int i = 2; i <= total; i++) {
if (a[i].score == a[i - 1].score) {
a[i].frank = a[i - 1].frank;
} else {
a[i].frank = t;
}
t++;
}
cout << total << endl;
for (int i = 1; i <= total; i++) {
cout << a[i].id << ' ' << a[i].frank << ' ' << a[i].lonum << ' ' << a[i].lrank << endl;
}
return 0;
}
边栏推荐
- 教你打印自己的日志 -- 如何自定义 log4j2 各组件
- Seven phases of CMS implementation
- Bit. Store: long bear market, stable stacking products may become the main theme
- 使用MySqlBulkLoader批量插入数据
- Blink SQL内置函数大全
- RANSAC的代码和原理
- 网络上开户买股票是否安全呢?刚接触股票,不懂求指导
- NVIDIA Clara-AGX-Developer-Kit installation
- Embracing cloud Nativity: Practice of Jiangsu Mobile order center
- Running lantern experiment based on stm32f103zet6 library function
猜你喜欢

Doctoral Dissertation of the University of Toronto - training efficiency and robustness in deep learning

国际数字经济学院、华南理工 | Unified BERT for Few-shot Natural Language Understanding(用于小样本自然语言理解的统一BERT)

Bit. Store: long bear market, stable stacking products may become the main theme

openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题

MySQL表的增删改查(基础)

Mathematical derivation from perceptron to feedforward neural network

SQL Server - Window Function - 解决连续N条记录过滤问题

深度学习和神经网络的介绍

429-二叉树(108. 将有序数组转换为二叉搜索树、538. 把二叉搜索树转换为累加树、 106.从中序与后序遍历序列构造二叉树、235. 二叉搜索树的最近公共祖先)

Array exercises follow up
随机推荐
maxwell 报错(连接为mysql 8.x)解决方法
[cloud based co creation] the "solution" of Digital Travel construction in Colleges and Universities
Character interception triplets of data warehouse: substrb, substr, substring
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
《第五项修炼》(The Fifth Discipline):学习型组织的艺术与实践
基于STM32F103ZET6库函数按键输入实验
深度学习和神经网络的介绍
基于STM32F103ZET6库函数蜂鸣器实验
MySQL表的增删改查(基础)
流程判断-三目运算-for循环
基于STM32F103ZET6库函数外部中断实验
SQL Server - Window Function - 解决连续N条记录过滤问题
NVIDIA Clara-AGX-Developer-Kit installation
Array exercises follow up
Crawl national laws and Regulations Database
binder hwbinder vndbinder
聊聊毕业季
爬取国家法律法规数据库
Making single test so simple -- initial experience of Spock framework
基于STM32F103ZET6库函数跑马灯实验