1025 PAT Ranking (25 分)

ranllist[i]可以通过复用一个vector代替;或者输入直接写入totallist(final list),用一个数标记位置,以便得到本场次的起始位置。

#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
struct testee{
    string id;
    int mark,group,local_rank,total_rank;
};
bool cmp(testee t1,testee t2){
    return (t1.mark==t2.mark)?(t1.id.compare(t2.id)<0):t1.mark>t2.mark;
}
int main()
{
    int N;
    cin>>N;
    vector<testee>ranklist[N];
    vector<testee>totallist;
    for (int i = 0; i < N; ++i) {
        int K;
        cin>>K;
        for (int j = 0; j < K; ++j) {
            testee temp;
            cin>>temp.id>>temp.mark;
            temp.group=i+1;
            ranklist[i].push_back(temp);
        }
        sort(ranklist[i].begin(),ranklist[i].end(),cmp);
        int local_count=1;
        ranklist[i][0].local_rank=1;
        totallist.push_back(ranklist[i][0]);
        for (int j = 1; j < K; ++j) {
            local_count++;
            ranklist[i][j].local_rank=(ranklist[i][j].mark==ranklist[i][j-1].mark)?ranklist[i][j-1].local_rank:local_count;
            totallist.push_back(ranklist[i][j]);
        }
    }
    sort(totallist.begin(),totallist.end(),cmp);
    int total_count=1;
    totallist[0].total_rank=1;
    cout<<totallist.size()<<endl;
    cout<<totallist[0].id<<" 1 "<<totallist[0].group<<" 1"<<endl;
    for (int i = 1; i < totallist.size(); ++i) {
        total_count++;
        totallist[i].total_rank=(totallist[i].mark==totallist[i-1].mark)?totallist[i-1].total_rank:total_count;
        cout<<totallist[i].id<<" "<<totallist[i].total_rank<<" "<<totallist[i].group<<" "<<totallist[i].local_rank<<endl;
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值