|
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:
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
题目大意
先给一个整数N,表示有N个考场
对于每个考场给一个M,表示该考场有M个学生
然后对于每个M,给出M个学生的考试信息
求每位学生得分在其所在考场中的排名以及总排名。
最后按该 总排名 > id编号升序 输出
输出格式
学号 总排名 所在考场编号 所在考场当中的排名
思路
结构体+sort排序
C/C++
#include<bits/stdc++.h>
using namespace std;
struct Student{
string id;
int number,score,rank;
}s;
bool cmp(const Student& x,const Student& y){
return x.score!=y.score ? x.score>y.score : x.id < y.id;
}
int main()
{
vector<Student> all,box;
int N,M;
cin >> N;
for(int z=1;z<=N;z++){
cin >> M;
s.number = z;
while (M--){
cin >> s.id >> s.score;
box.push_back(s);
}
sort(box.begin(),box.end(),cmp);
box[0].rank = 1;
for(int z1=1;z1<box.size();z1++){
if(box[z1].score==box[z1-1].score) box[z1].rank = box[z1-1].rank;
else box[z1].rank = z1+1;
}
for(const auto& x:box) all.push_back(x);
box.clear();
}
sort(all.begin(),all.end(),cmp);
cout << all.size() << endl;
int lastScore = all[0].score,lastRank=1;
for(int z=0;z<all.size();z++){
if(all[z].score!=lastScore){
lastScore = all[z].score;
lastRank = z+1;
}
printf("%s %d %d %d\n",all[z].id.c_str(),lastRank,all[z].number,all[z].rank);
}
return 0;
}

本程序为PAT考试成绩合并工具,可处理多个考场的成绩排名,并输出最终排名及详细信息。输入包括考场数量、各考场考生数量及其成绩,输出按总排名和ID编号升序排列的考生信息。
267

被折叠的 条评论
为什么被折叠?



