pat-1025 PAT Ranking

不同地点一起排序
先组内排序,再全局排序
将小组添加进全局

vector拼接
globallist.insert(globallist.end(),locallist.begin(),locallist.end());



#include<iostream>
using namespace std;
#include<vector>
#include<string>
#include<algorithm>

struct Score
{
string id;
int score;
int local;
int global;
int location;
};

bool sortByScore(Score a,Score b)
{
if(a.score != b.score)
return a.score > b.score;
else
return a.id < b.id;
}


int main()
{
vector<Score> globallist;
vector<Score> locallist;

int N;
int K;

cin>>N;
for(int n=1;n<=N;n++)
{
cin>>K;
while(K--)
{
Score s;
cin >> s.id;
cin >> s.score;
s.location = n;
locallist.push_back(s);
}

sort(locallist.begin(),locallist.end(),sortByScore);
//rank
for(int i=0;i<locallist.size();i++)
{
if(i!=0 && locallist[i].score == locallist[i-1].score)
locallist[i].local = locallist[i-1].local;
else
locallist[i].local = i+1;
}
//add
globallist.insert(globallist.end(),locallist.begin(),locallist.end());
locallist.clear();
}

//rank
cout<<globallist.size()<<endl;
sort(globallist.begin(),globallist.end(),sortByScore);
for(int i=0;i<globallist.size();i++)
{
if(i!=0 && globallist[i].score == globallist[i-1].score)
globallist[i].global = globallist[i-1].global;
else
globallist[i].global = i+1;
cout<<globallist[i].id<<" "<<globallist[i].global<<" "<<globallist[i].location<<" "<<globallist[i].local<<endl;
}


}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值