最终排名 sdut 2446

最终排名

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2446

第四届山东理工大学ACM网络编程擂台赛比赛完后需要产生一个最终排名,排名按照题数多少来决定。但是有太多的队伍参与,手动计算排名已经不能满足比赛的需求。现在有一份名单记录各个队伍的ID和做出的题目数,需要你写一个程序,产生最终的排名。

为了简化题目,这里的排名规则为:做出题目数量多的队伍排在前面,如果题数相等,保持输入时的相对顺序不要改变。

输入

 第一行包含一个正整数T( 1≤T≤15),表示有T组测试数据。每组数据第一行有一个正整数N(1< N≤10000),表示队伍数量。接下来N 行包含两个整数,1≤ID≤10^7, 0≤M≤100。ID为队伍的编号,M为做出的题数。

输出

 每组数据输出包含N行,第i行有两个整数,ID和M表示排在第i位的队伍的ID和做出的题数。

示例输入

1
8
1 2
16 3
11 2
20 3
3 5
26 4
7 1
22 4

示例输出

3 5
26 4
22 4
16 3
20 3
1 2
11 2
7 1

提示

 代码:
 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<algorithm>
 4 using namespace std;
 5 struct vode
 6 {
 7     int id,chengji,shunxu;
 8 }f[1000];
 9 int cmp(const vode a,const vode b)
10 {
11     if(a.chengji>b.chengji)return 1;
12     else if(a.chengji<b.chengji)return 0;
13     else
14     {
15         if(a.shunxu>b.shunxu)return 0;
16         else return 1;
17     }
18 }
19 int main()
20 {
21     int zong ;
22     cin>>zong;
23     while(zong--)
24     {
25       int t;
26       cin>>t;
27       int i,j;
28       for(i=0;i<=t-1;i++)
29       {
30           cin>>f[i].id>>f[i].chengji;
31           f[i].shunxu=i;
32       }
33       sort(f,f+t,cmp);
34       for(i=0;i<=t-1;i++)
35           cout<<f[i].id<<" "<<f[i].chengji<<endl;
36     }
37     return 0;
38 }
View Code

题意很清楚,代码很简单,但是要注意sort函数的用法

 
原文地址:https://www.cnblogs.com/kuangdaoyizhimei/p/3389935.html