1025. PAT Ranking (25)

传送门://https://www.patest.cn/contests/pat-a-practise/1025

AC代码

#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <string.h>
#include <unordered_map>
using namespace std;
struct student{
    char id[14];
    int score,localTest,localRank,totalRank;
    bool operator>(const student &target){
        if(score!=target.score)
            return score>target.score;
        else
            return strcmp(id, target.id)<0;
    }
};
int main(){
    int n,m;
    scanf("%d",&n);
    vector<student>allStudents;
    vector<vector<int>>LocalsocreCount(n,vector<int>(101,0));
    vector<int>AllsocreCount(101,0);
    int start = 0,end=0;
    for (int i=0; i<n; ++i) {
        scanf("%d",&m);
        for(int j = 0;j<m;++j)
        {
            student s;
            scanf("%s %d",s.id,&s.score);
            s.localTest = i+1;
            allStudents.push_back(s);
            LocalsocreCount[i][s.score]++;
            AllsocreCount[s.score]++;
        }
        for (int j=99; j>=0; j--)
            LocalsocreCount[i][j]+= LocalsocreCount[i][j+1];
        end = end +m;
        for (int j = start; j<end; j++) {
            if (allStudents[j].score==100) {
                allStudents[j].localRank = 1;
            }else
                allStudents[j].localRank = LocalsocreCount[i][allStudents[j].score+1]+1;
        }
        start = end;
    }
    for (int i=99; i>=0; i--) {
        AllsocreCount[i]+= AllsocreCount[i+1];
    }
    sort(allStudents.begin(), allStudents.end(), [](student a,student b){
        return a>b;
    });
    printf("%d\n",(int)allStudents.size());
    for (int i=0; i<allStudents.size(); ++i) {
        if(allStudents[i].score == 100)
            allStudents[i].totalRank = 1;
        else
            allStudents[i].totalRank = AllsocreCount[allStudents[i].score+1]+1;
        printf("%s %d %d %d\n",allStudents[i].id,allStudents[i].totalRank,allStudents[i].localTest,allStudents[i].localRank);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值