这种排序题做过好多遍了
主要是需要注意相同成绩的人具有相同名次
但是输出的时候如果成绩相同需要将学号小的先输出
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <string>
using namespace std;
const int M = 3e4+5;
struct stu{
string no;
int score, rk, idx;
bool operator < (const stu a)const{
if(score != a.score) return score > a.score;
return no < a.no;
}
}E[M];
struct rng{
string no;
int score;
bool operator < (const rng a)const{
if(score != a.score) return score > a.score;
return no < a.no;
}
}T[305];
int main(){
int N, K, cnt = 0;
string no;
cin>>N;
int j = 0;
int last;
for(int v = 1; v <= N; v++){
cin>>K;
cnt += K;
for(int i =0; i < K; i++){
cin>>T[i].no>>T[i].score;
}
sort(T, T+K);
for(int i = 0; i < K; i++){
E[i+j].no = T[i].no;
E[i+j].score = T[i].score;
E[i+j].idx = v;
if(i==0 || T[i].score != T[i-1].score) {
E[i+j].rk = i+1;
last = i+1;
}else E[i+j].rk = last;
}
j = j+K;
}
sort(E, E+cnt);
cout<<cnt<<endl;
for(int i = 0; i < cnt; i++){
cout<<E[i].no<<" ";
if(i==0 || E[i].score != E[i-1].score){
cout<<i+1<<" ";
last = i+1;
}else cout<<last<<" ";
cout<<E[i].idx<<" "<<E[i].rk<<endl;
}
return 0;
}