1025 PAT Ranking

本程序为PAT考试成绩合并工具,可处理多个考场的成绩排名,并输出最终排名及详细信息。输入包括考场数量、各考场考生数量及其成绩,输出按总排名和ID编号升序排列的考生信息。

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.


Sample Input:

2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85

Sample Output:

9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4

题目大意

先给一个整数N,表示有N个考场

对于每个考场给一个M,表示该考场有M个学生

然后对于每个M,给出M个学生的考试信息

求每位学生得分在其所在考场中的排名以及总排名。

最后按该 总排名 > id编号升序 输出

 

 输出格式

学号 总排名 所在考场编号 所在考场当中的排名

思路

结构体+sort排序


C/C++ 

#include<bits/stdc++.h>
using namespace std;
struct Student{
    string id;
    int number,score,rank;
}s;
bool cmp(const Student& x,const Student& y){
    return x.score!=y.score ? x.score>y.score : x.id < y.id;
}
int main()
{
    vector<Student> all,box;
    int N,M;
    cin >> N;
    for(int z=1;z<=N;z++){
        cin >> M;
        s.number = z;
        while (M--){
            cin >> s.id >> s.score;
            box.push_back(s);
        }
        sort(box.begin(),box.end(),cmp);
        box[0].rank = 1;
        for(int z1=1;z1<box.size();z1++){
            if(box[z1].score==box[z1-1].score) box[z1].rank = box[z1-1].rank;
            else box[z1].rank = z1+1;
        }
        for(const auto& x:box) all.push_back(x);
        box.clear();
    }

    sort(all.begin(),all.end(),cmp);
    cout << all.size() << endl;
    int lastScore = all[0].score,lastRank=1;
    for(int z=0;z<all.size();z++){
        if(all[z].score!=lastScore){
            lastScore = all[z].score;
            lastRank = z+1;
        }
        printf("%s %d %d %d\n",all[z].id.c_str(),lastRank,all[z].number,all[z].rank);
    }

    return 0;
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三块不一样的石头

十分满意,一分打赏~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值