码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 甲级 A1025 (2019/02/17)

时间:2019-02-24 10:35:34      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:ret   \n   cal   print   cstring   max   mes   ++   i++   

#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;
}

PAT 甲级 A1025 (2019/02/17)

标签:ret   \n   cal   print   cstring   max   mes   ++   i++   

原文地址:https://www.cnblogs.com/zjsaipplp/p/10425253.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!