代码如下:
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 struct ran{ //定义出rank选手的需要的信息 7 string number; //选手编号 8 int bianhao; //组号 9 int score; //成绩10 int order; //组内排名11 int order_total; //总体排名12 friend bool operator <(ran r1,ran r2){ //重载小于号13 if(r1.score < r2.score) return true;14 else if(r1.score == r2.score && r2.number < r1.number) return true;15 return false;16 }17 };18 int main(){19 priority_queue r; //优先队列进行保存20 priority_queue r_2;21 int n,m,k,sum = 0,paiming = 0,stem; //paiming用来记录排名,stem用来记录排名的备份22 cin >> n; //输入23 ran rx;24 for(int i = 0; i < n; i++){25 cin >> m;26 sum += m;27 for(int j = 0; j < m; j++){28 cin >> rx.number >> rx.score; //输入29 rx.bianhao = i+1;30 r.push(rx);31 }32 paiming = 1,stem = 1;33 while(!r.empty()){ //计算组内排名34 rx = r.top(); //取出当前最高分35 r.pop(); //出队列36 rx.order = paiming; //paiming赋值37 if(rx.score != r.top().score) //有相同分数时的处理38 paiming = stem+1;39 //else paiming++;40 stem++; //备份一直自加41 r_2.push(rx); //重新入队列42 }43 }44 cout << sum << endl;45 paiming = 1,stem = 1;46 while(!r_2.empty()){47 rx = r_2.top();48 r_2.pop();49 rx.order_total = paiming;50 cout << fixed << rx.number << " " << rx.order_total << " " << rx.bianhao << " " << rx.order << endl;51 if(rx.score != r_2.top().score) paiming = stem+1;52 //else paiming++;53 stem++;54 //r.push(rx);55 }56 57 // for(int i = 0; i < sum; i++){58 // rx = r.top();59 // r.pop();60 // cout << rx.number << " " << rx.order_total << " " << rx.bianhao << " " << rx.order << endl;61 // }62 //cout << "hello world";63 return 0;64 }