PAT A 1025 PAT Ranking

一、题目(Translated)

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.
编程能力测试(PAT)是浙江大学计算机科学与技术学院举办的一场考试。每场考试同时在多个地区进行,考试后,将尽快生成考试排名名单。现在要求你编写程序,正确的整合列表及生成排名。

输入格式:
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.
每个输入包含一个测试用例。每个测试用例,第一行给出一个正数N (≤100)为测试地区的数量。然后给出N个列表,每个列表第一行给出一个正数K (≤300)为该地区的考生信息数量,紧跟着K行考生信息,含:准考证号(13位数字);该考生总成绩。同一行的数字之间以空格分隔。

输出格式:
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.
考试地区从1至N编号。输出按总成绩非递减排序。总成绩相同者并列排名,并按准考证号非递减排序;

输入样例:
2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85

输出样例:
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.

二、思路

STEP1:
建立考生结构体:{准考证号,总分,地区编号,总排名,地区排名};
STEP2:
建立考生数组;
循环N次,每次读入K个考生信息;输入并添加地区编号,完成后对该地区的考生信息进行排序,按要求添加地区排名;
STEP3:
对所有数据排序,添加总排名信息;
STEP4:
输出;

三、代码实现

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef struct
{
    int finRank, locRank, nLoc, score;
    string ID;
}Testee;
int main()
{
    int N;
    Testee t;
    cin >> N;
    vector<Testee> T;
    for( int i = 1, K; i <= N; ++i )
    {
        cin >> K;
        for( int j = 0; j < K; ++j )
        {
            cin >> t.ID >> t.score;
            t.nLoc = i;
            T.push_back(t);
        }
        sort( T.end() - K, T.end(), [](Testee a, Testee b) { return a.score > b.score; } );
        T[ T.size() - K ].locRank = 1;
        for( int j = K - 1; j > 0 ; --j )
            if( T[ T.size() - j ].score == T[ T.size() - j - 1 ].score )
                T[ T.size() - j ].locRank = T[ T.size() - j - 1 ].locRank;
            else T[ T.size() - j ].locRank = K - j + 1;
    }
    sort( T.begin(), T.end(), [](Testee a, Testee b) {  if( a.score != b.score ) return a.score > b.score; else return a.ID < b.ID; } );
    T[0].finRank = 1;
    for( int i = 1; i < T.size(); ++i  )
        if( T[ i ].score == T[ i - 1 ].score )
            T[ i ].finRank = T[ i - 1 ].finRank;
           else T[ i ].finRank = i + 1;
    cout << T.size() << endl;
    for( int i = 0; i < T.size(); ++i )
        cout << T[i].ID << " " << T[i].finRank << " " << T[i].nLoc << " " << T[i].locRank << endl;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值