博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT 甲级 1025 1025 PAT Ranking
阅读量:5111 次
发布时间:2019-06-13

本文共 3148 字,大约阅读时间需要 10 分钟。

 

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:

251234567890001 951234567890005 1001234567890003 951234567890002 771234567890004 8541234567890013 651234567890011 251234567890014 1001234567890012 85

Sample Output:

91234567890005 1 1 11234567890014 1 2 11234567890001 3 1 21234567890003 3 1 21234567890004 5 1 41234567890012 5 2 21234567890002 7 1 51234567890013 8 2 31234567890011 9 2 4

代码:

#include 
using namespace std;int T;int r[30010];int sum = 0;struct Node{ char id[20]; int score; int FR; int LN; int LR;}node[30010];bool cmp1(const Node& a, const Node& b) { if(a.score != b.score) return a.score > b.score; return strcmp(a.id, b.id) < 0;}int main() { scanf("%d", &T); for(int t = 1; t <= T; t ++) { scanf("%d", &r[t]); for(int i = 1; i <= r[t]; i ++) { sum ++; scanf("%s%d", node[sum].id, &node[sum].score); node[sum].LN = t; } sort(node + sum - r[t] + 1, node + sum + 1, cmp1); //for(int i = sum - r[t] + 1; i <= sum; i ++) // printf("%s\n", node[i].id); //printf("%d %d\n", sum - r[t] + 1, sum); node[sum - r[t] + 1].LR = 1; for(int i = sum - r[t] + 2; i <= sum + 1; i ++) { if(node[i].score == node[i - 1].score) node[i].LR = node[i - 1].LR; else node[i].LR = i - (sum - r[t]); } //for(int i = sum - r[t] + 1; i <= sum + 1; i ++) //printf("%s %d\n", node[i].id, node[i].LR); } sort(node + 1, node + 1 + sum, cmp1); node[1].FR = 1; for(int i = 2; i <= sum; i ++) { if(node[i].score == node[i - 1].score) node[i].FR = node[i - 1].FR; else node[i].FR = i; } printf("%d\n", sum); for(int i = 1; i <= sum; i ++) { printf("%s %d %d %d\n", node[i].id, node[i].FR, node[i].LN, node[i].LR); } return 0;}

  

转载于:https://www.cnblogs.com/zlrrrr/p/9841852.html

你可能感兴趣的文章
df和du显示的磁盘空间使用情况不一致的原因及处理
查看>>
[无关] 胡言乱语3
查看>>
Leetcode 29. Divide Two Integers
查看>>
thinkPHP--SQL查询
查看>>
winrar 弹窗处理
查看>>
关于IO流的抽象类
查看>>
2019.1.26
查看>>
伪静态的实现方法:IIS环境下配置
查看>>
Selenium-webdriver系列教程(三)————如何执行一段js脚本
查看>>
使用debussy完成自动仿真
查看>>
MyEclipse中Web项目的发布和运行
查看>>
【模板】最短路
查看>>
理解 Lua 的那些坑爹特性
查看>>
Windows WMIC命令使用详解(附实例)
查看>>
如何从Powerdesigner进行数据建模并生成SQL脚本
查看>>
发现微信支付bug
查看>>
MVC过滤器---异常处理过滤器
查看>>
你不知道的常用 代码分析 规范
查看>>
rlwrap
查看>>
断点续传
查看>>