PAT 甲级 A1025 (2019/02/17)
Posted zjsaipplp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT 甲级 A1025 (2019/02/17)相关的知识,希望对你有一定的参考价值。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 30010;
struct Student{
char id[15];
int score;
int local_number;
int local_rank;
}stu[maxn];
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 main(){
int test_room_number, examinee_number, acount_stu = 0;
scanf("%d", &test_room_number);
for(int i = 0; i < test_room_number; i++){
scanf("%d", &examinee_number);
for(int j = 0; j < examinee_number; j++){
scanf("%s %d", stu[acount_stu].id, &stu[acount_stu].score);
stu[acount_stu].local_number = i + 1;
acount_stu++;
}
sort(stu + acount_stu - examinee_number, stu + acount_stu, cmp);
stu[acount_stu - examinee_number].local_rank = 1;
for(int k = acount_stu - examinee_number + 1; k < acount_stu; k++){
if(stu[k].score == stu[k - 1].score){
stu[k].local_rank = stu[k - 1].local_rank;
}else{
stu[k].local_rank = k + 1 - (acount_stu - examinee_number);
}
}
}
printf("%d
", acount_stu);
sort(stu, stu + acount_stu, cmp);
int r = 1;
for(int j = 0; j < acount_stu; j++){
if(j > 0 && stu[j].score != stu[j - 1].score){
r = j + 1;
}
printf("%s %d %d %d
",stu[j].id, r, stu[j].local_number, stu[j].local_rank);
}
return 0;
}
以上是关于PAT 甲级 A1025 (2019/02/17)的主要内容,如果未能解决你的问题,请参考以下文章