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;
}