结构体排序题
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
struct Rank{
char registration_number[15];
int score;
int final_rank,location_number,local_rank;
bool operator < (const Rank &a) const{
if(score != a.score)
return score > a.score;
else{
return strcmp(registration_number,a.registration_number)<0;
}
}
};
vector<Rank> global;
int main(){
int n,k,sum=0,tmp_rank=2;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&k);
sum+=k;
vector<Rank> local;
for(int j=1;j<=k;j++){
Rank tmp;
scanf("%s",tmp.registration_number);
scanf("%d",&tmp.score);
tmp.location_number=i;
tmp.local_rank = tmp.final_rank = 1;
local.push_back(tmp);
}
sort(local.begin(),local.end());
tmp_rank=2;
for(int j=0;j<local.size()-1;j++){
if(local[j].score==local[j+1].score){
local[j+1].local_rank=local[j].local_rank;
tmp_rank++;
}
else{
local[j+1].local_rank=tmp_rank;
tmp_rank++;
}
global.push_back(local[j]);
}
global.push_back(local[local.size()-1]);
}
printf("%d\n",sum);
sort(global.begin(),global.end());
tmp_rank=2;
for(int j=0;j<global.size();j++){
if(global[j].score==global[j+1].score){
global[j+1].final_rank=global[j].final_rank;
tmp_rank++;
}
else{
global[j+1].final_rank=tmp_rank;
tmp_rank++;
}
}
for(int j=0;j<global.size();j++){
printf("%s %d %d %d\n",global[j].registration_number,global[j].final_rank,global[j].location_number,global[j].local_rank);
}
return 0;
}