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\n", 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\n",stu[j].id, r, stu[j].local_number, stu[j].local_rank);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/zjsaipplp/p/10425253.html