1025 PAT Ranking

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive number N (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

Output Specification:

For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

registration_number final_rank location_number local_rank

The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

注意事项

如果第三个测试点和第四个测试点过不去,代码中若使用了sort的话,看看sort的范围是否大于实际需要排序的范围,大于实际的范围,示例也能过,但最后两个测试点过不了。

代码

#include<iostream>
#include "algorithm"
#include "cstring"

struct student {
    char id[15];
    int score;
    int rank;
    int org;
    int orgRank;
} stu[30010];

bool cmp (student a, student b) {  //以a为基准
    if (a.score != b.score) return a.score > b.score; //按分数从大到小排
    else return strcmp(a.id,b.id)<0;
}

int main() {
    int n,num=0;
    scanf("%d",&n);
    for (int j=1; j<=n;j++) {
       int m;
        scanf("%d",&m);
        for (int i =0; i<m;i++) {
            scanf("%s %d",stu[num].id,&stu[num].score);
            stu[num].org = j;
            num++;
        }
        std::sort(stu + num - m,stu + num,cmp);

        stu[num - m].orgRank = 1;
        int k =2;
        for(int index = num-m +1;index<num;index++) {
            if (stu[index].score == stu[index - 1].score ) {
                stu[index].orgRank = stu[index-1].orgRank;
            } else {
                stu[index].orgRank=k;
            }
            k++ ;
        }

    }
    std::sort(stu,stu + num, cmp);
    stu[0].rank = 1;
    printf("%d\n",num);
    printf("%s %d %d %d\n",stu[0].id,stu[0].rank,stu[0].org,stu[0].orgRank);
    int k =2;
    for (int i = 1; i < num; ++i) {
        if (stu[i].score == stu[i - 1].score ) {
            stu[i].rank = stu[i-1].rank;

        } else {
            stu[i].rank=k;
        }
        k++ ;
        printf("%s %d %d %d\n",stu[i].id,stu[i].rank,stu[i].org,stu[i].orgRank);
    }

    return 0;
}

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值