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 (), the number of test locations. Then ranklists follow, each starts with a line containing a positive integer (), the number of testees, and then lines con‐taining 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 . 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
很明显 看输入输出
先输出总共多少人
然后输出总成绩排名从小到大的 (排名一样输出号码小的)
输出总排名
输出是第几考场的
输出在他自己的考场的排名
思路就是先考场内排序 完了再总排序 注意grade有的人会相同 相同的就让他和他上一个的rank相同
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
const int N = 1e5+10;
int k;
struct G
{
string s;
int grade;
int id;
int rank1;
int rank;
bool operator<(const G &b) const
{
if(grade != b.grade) return grade>b.grade;
else return s < b.s;
}
}g[N];
int main()
{
cin>>n;
int idx = 0;
for(int i=1;i<=n;i++)
{
cin>>k;
int t = k;
while(t--)
{
cin>>g[idx].s>>g[idx].grade;
g[idx].id = i;
idx++;
}
sort(g+idx-k,g+idx);
t = 1;
for(int j=idx-k;j<idx;j++)
{
if(j != idx-k && g[j].grade == g[j-1].grade) g[j].rank1 = g[j-1].rank1;
else g[j].rank1 = t;
t++;
}
}
sort(g,g+idx);
int t = 1;
for(int i=0;i<idx;i++)
{
if(i != 0 && g[i].grade == g[i-1].grade) g[i].rank = g[i-1].rank;
else g[i].rank = t;
t++;
}
cout<<idx<<endl;
for(int i=0;i<idx;i++)
{
cout<<g[i].s<<' '<<g[i].rank<<' '<<g[i].id<<' '<<g[i].rank1<<endl;
}
return 0;
}