PAT 甲级 1025 PAT Ranking
作者:
自由基
,
2021-08-06 21:53:42
,
所有人可见
,
阅读 225
/*
分数相同的排名也需要相同的处理方法
如:90 90 90 87 85 84 84 80
1 1 1 4 5 6 6 8
*/
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
const int N = 30010;
struct Student
{
char id[20];
int score;
int l_num;
int l_rank;
}stu[N];
bool cmp( Student a, Student b ) {
if ( a.score != b.score ) return a.score > b.score;
else return strcmp(a.id, b.id ) < 0;
}
int n,k;
int main( ){
scanf("%d", &n);
int cnt = 0;
for ( int i = 1; i<=n; i++ ){
scanf("%d", &k);
for ( int j = 0; j < k; j++ ) {
scanf("%s %d", stu[cnt].id, &stu[cnt].score);
stu[cnt].l_num = i;
cnt++;
}
sort(stu + cnt - k, stu+cnt, cmp );
stu[cnt-k].l_rank = 1;
for ( int j = cnt - k+1; j < cnt; j++ ) {
if ( stu[j].score == stu[j-1].score ) {
stu[j].l_rank = stu[j-1].l_rank;
}
else {
stu[j].l_rank = j + 1 - (cnt - k);
}
}
}
printf("%d\n", cnt);
sort(stu, stu+cnt,cmp);
int r = 1;
for ( int i = 0; i < cnt; i++ ) {
if ( i > 0 && stu[i].score != stu[i-1].score ) {
r = i + 1;
}
printf("%s ", stu[i].id);
printf("%d %d %d\n", r, stu[i].l_num, stu[i].l_rank);
}
return 0;
}