AcWing 1502. PAT 排名
原题链接
中等
作者:
Value
,
2020-06-01 09:45:32
,
所有人可见
,
阅读 447
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 30010;
struct node{
string id;
int score;
int final_rank, location_number, local_rank;
void toString(){
cout << id << " " << final_rank << " " << location_number << " " << local_rank << endl;
}
};
node stu[N], tmp[N];
int way;
bool cmp(node a, node b){
if(a.score != b.score) return a.score > b.score;
else return a.id < b.id;
}
int main(){
int region;
cin >> region;
int n, cnt;
cnt = 0;
for(int i = 1; i <= region; i ++ ){
cin >> n;
for(int j = 0; j < n; j ++ ){
cin >> tmp[j].id >> tmp[j].score;;
tmp[j].location_number = i;
}
sort(tmp, tmp + n, cmp);
for(int j = 0; j < n; j ++ ){
if(!j || tmp[j].score != tmp[j - 1].score) tmp[j].local_rank = j + 1;
else tmp[j].local_rank = tmp[j - 1].local_rank;
stu[cnt ++ ] = tmp[j];
}
}
sort(stu, stu + cnt, cmp);
for(int i = 0; i < cnt; i ++ ){
if(!i || stu[i].score != stu[i - 1].score) stu[i].final_rank = i + 1;
else stu[i].final_rank = stu[i - 1].final_rank;
}
cout << cnt << endl;
for(int i = 0; i < cnt ; i ++ ) stu[i].toString();
return 0;
}