最终排名
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
第四届山东理工大学ACM网络编程擂台赛比赛完后需要产生一个最终排名,排名按照题数多少来决定。但是有太多的队伍参与,手动计算排名已经不能满足比赛的需求。现在有一份名单记录各个队伍的ID和做出的题目数,需要你写一个程序,产生最终的排名。
为了简化题目,这里的排名规则为:做出题目数量多的队伍排在前面,如果题数相等,保持输入时的相对顺序不要改变。
Input
第一行包含一个正整数T( 1 ≤ T ≤ 15),表示有T组测试数据。每组数据第一行有一个正整数N(1 < N ≤ 10000),表示队伍数量。接下来N 行包含两个整数,1 ≤ ID ≤ 10^7, 0 ≤ M ≤ 100。ID为队伍的编号,M为做出的题数。
Output
每组数据输出包含N行,第i行有两个整数,ID和M表示排在第i位的队伍的ID和做出的题数。
Example Input
1
8
1 2
16 3
11 2
20 3
3 5
26 4
7 1
22 4
Example Output
3 5
26 4
22 4
16 3
20 3
1 2
11 2
7 1
#include <bits/stdc++.h> using namespace std; const int N=10005; int T,n; struct node { int id; int ac; int shunxu; }team[N]; bool cmp(const node& x,const node& y) { if(x.ac==y.ac) return x.shunxu<y.shunxu; else return x.ac>y.ac; } int main() { cin>>T; while(T--) { cin>>n; for(int i=1;i<=n;i++) { cin>>team[i].id>>team[i].ac; team[i].shunxu=i; } sort(team+1,team+1+n,cmp); for(int i=1;i<=n;i++) cout<<team[i].id<<" "<<team[i].ac<<endl; } return 0; }