PAT甲级——A1025 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
简单的排序题,使用结构体
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct Node
{
string No;
int score, final_rank, location_num, local_rank;
}; bool cmp(Node* a, Node* b)
{
return (a->score == b->score) ? (a->No < b->No) : (a->score > b->score);
}
int N, K;
vector<Node*>allPerson;
int main()
{
cin >> N;
for (int i = ; i <= N; ++i)
{
cin >> K;
vector<Node*>temp;
for (int j = ; j < K; ++j)
{
Node* node = new Node;
cin >> node->No >> node->score;
node->location_num = i;
temp.push_back(node);
}
sort(temp.begin(), temp.end(), cmp);
for (int j = ; j < temp.size(); ++j)
{
if (j > && temp[j]->score == temp[j - ]->score)
temp[j]->local_rank = temp[j - ]->local_rank;
else
temp[j]->local_rank = j + ;
}
allPerson.insert(allPerson.end(), temp.begin(), temp.end());
}
sort(allPerson.begin(), allPerson.end(), cmp);
cout << allPerson.size() << endl;
for (int j = ; j < allPerson.size(); ++j)
{
if (j> && allPerson[j]->score == allPerson[j - ]->score)
allPerson[j]->final_rank = allPerson[j - ]->final_rank;
else
allPerson[j]->final_rank = j + ;
cout << allPerson[j]->No << " " << allPerson[j]->final_rank << " " <<
allPerson[j]->location_num << " " << allPerson[j]->local_rank << endl;
}
return ;
}
PAT甲级——A1025 PAT Ranking的更多相关文章
- PAT 甲级 1141 PAT Ranking of Institutions
https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...
- PAT 甲级 1025 PAT Ranking
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- PAT甲级——1025 PAT Ranking
1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...
- PAT 甲级 1025.PAT Ranking C++/Java
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Z ...
- PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)
题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...
- PAT甲级1075 PAT Judge
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805393241260032 题意: 有m次OJ提交记录,总共有k道 ...
- PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)
1075 PAT Judge (25分) The ranklist of PAT is generated from the status list, which shows the scores ...
- PAT甲级——A1075 PAT Judge
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- A1025 PAT Ranking (25)(25 分)
A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...
随机推荐
- iserver中的服务数据迁移
今天需要将iserver测试服务器上的空间数据服务(数据源是Oracle Plus)迁移到客户的正式服务器,原想需要很大的工作量,其实是这样简单: 一.保证客户的iserver环境都已安装正确.对于o ...
- spss modeler出现使用错误提
spss modeler出现使用错误提 1.对字段"compensation汇总导出"指定的类型不充分 问题: 为了分析需要,我加了一个"字段选项"--&quo ...
- Linux后台运行java的jar包后台运行java -jar 命令
为什么java -jar 的命令终端的窗口关闭就停止运行了??tomcat中war的就不会? 关闭终端的窗口相当于ctrl+c的命令,关闭了窗口就相当于停止了java -jar这个进程,即ctrl+c ...
- selenium基础(脚本模块化)
selenium基础(脚本模块化)
- selenium基础(多表单切换、多窗口切换)
一.多表单的切换 frame:HTML页面中的一中框架,主要作用是在当前页面中指定区域显示另一页面元素: (HTML语言中,frame/iframe标签为表单框架) 在web ...
- POJ3321Apple Tree
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 39566 Accepted: 11727 Descript ...
- loj6247 九个太阳
题意: k<=2^20,n<=10^15. 标程: #include<cstdio> using namespace std; typedef long long ll; ; ...
- P1082 同余方程(扩欧模板)
https://www.luogu.org/problem/P1082 #include <iostream> #include <cstdio> #include <q ...
- leetcode-106-从中序和后序遍历构造二叉树
题目描述: 方法一:O(n) O(n) class Solution: def buildTree(self, inorder: List[int], postorder: List[int]) -& ...
- AMPQ
AMPQ AMQP,即Advanced Message Queuing Protocol,高级消息队列协议, 是`应用层协议的一个开放标准,为面向消息的中间件设计`. 由于AMQP是一个网络协议,所以 ...