传送门://https://www.patest.cn/contests/pat-a-practise/1025
AC代码
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <string.h>
#include <unordered_map>
using namespace std;
struct student{
char id[14];
int score,localTest,localRank,totalRank;
bool operator>(const student &target){
if(score!=target.score)
return score>target.score;
else
return strcmp(id, target.id)<0;
}
};
int main(){
int n,m;
scanf("%d",&n);
vector<student>allStudents;
vector<vector<int>>LocalsocreCount(n,vector<int>(101,0));
vector<int>AllsocreCount(101,0);
int start = 0,end=0;
for (int i=0; i<n; ++i) {
scanf("%d",&m);
for(int j = 0;j<m;++j)
{
student s;
scanf("%s %d",s.id,&s.score);
s.localTest = i+1;
allStudents.push_back(s);
LocalsocreCount[i][s.score]++;
AllsocreCount[s.score]++;
}
for (int j=99; j>=0; j--)
LocalsocreCount[i][j]+= LocalsocreCount[i][j+1];
end = end +m;
for (int j = start; j<end; j++) {
if (allStudents[j].score==100) {
allStudents[j].localRank = 1;
}else
allStudents[j].localRank = LocalsocreCount[i][allStudents[j].score+1]+1;
}
start = end;
}
for (int i=99; i>=0; i--) {
AllsocreCount[i]+= AllsocreCount[i+1];
}
sort(allStudents.begin(), allStudents.end(), [](student a,student b){
return a>b;
});
printf("%d\n",(int)allStudents.size());
for (int i=0; i<allStudents.size(); ++i) {
if(allStudents[i].score == 100)
allStudents[i].totalRank = 1;
else
allStudents[i].totalRank = AllsocreCount[allStudents[i].score+1]+1;
printf("%s %d %d %d\n",allStudents[i].id,allStudents[i].totalRank,allStudents[i].localTest,allStudents[i].localRank);
}
return 0;
}