题目:https://www.patest.cn/contests/pat-a-practise/1025
//1025. PAT Ranking (25)
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct stu
{
char id[15];
int rank;
int local;
int local_rank;
int score;
}Stu[30000];
bool cmp(stu a, stu b)
{
if(a.score!=b.score)
return a.score>b.score;
else
return strcmp(a.id,b.id)<0;
}
int main()
{
int N=0,K=0,Total=0,i=0,j=0;
scanf("%d",&N);
while(i<N)
{
scanf("%d",&K);
j=0;
while(j<K)
{
scanf("%s %d",Stu[j+Total].id,&Stu[j+Total].score);
Stu[j+Total].local = i+1;
j++;
}
sort(Stu+Total, Stu+Total+K, cmp);
Stu[Total].local_rank = 1;
for(j=1; j<K; j++)
{
if(Stu[j+Total].score == Stu[j+Total-1].score)
Stu[j+Total].local_rank = Stu[j+Total-1].local_rank;
else
Stu[j+Total].local_rank = j + 1;
}
Total += K;
i++;
}
sort(Stu, Stu+Total, cmp);
Stu[0].rank = 1;
for(j=1; j<Total; j++)
{
if(Stu[j].score == Stu[j-1].score)
Stu[j].rank = Stu[j-1].rank;
else
Stu[j].rank = j + 1;
}
printf("%d\n",Total);
for(i=0; i<Total; i++)
printf("%s %d %d %d\n",Stu[i].id,Stu[i].rank,Stu[i].local,Stu[i].local_rank);
return 0;
}