标签:结构体 排序
链接:click here
题意:
A Simple Problem
时间限制:3000 ms | 内存限制:65535 KB
难度:2
-
描述
- You know, just as the title imply, this is a simple problem. In a contest, given the team-id, solved, penalty of all the teams, tell me the champion.If the numbers of solved problem
of two team are different, the rank of the one who solves more problems is higher. Otherwise, if the the penalties of two team are different, the rank of the one who has less penalty is higher. Otherwise, the rank of the one whose team-id‘s lexicographic order
is earlier than the other is higher.
-
输入
- The first line of the input is an integer T which stands for the number of test cases. Then T test cases follow.
The first line of test case is a number n, which is the number of team in a contest. Then n line(s) follow. Each line contain a string, and two integers: str, s( 0 <= s <= 15 ), p(0<=p <= 20000), separated by a blank indicating that there is a team whose id
is str,the number of solved problem is s, and the penalty is p.
constraints:
n is in the range of [1 100].
Each team-id does not contain any blanks.
The length of team-id is in the range of[1, 20].
Any two teams will not have the same team-id. -
输出
- For each test case, output one line with an string indicating the the champion.
-
样例输入
-
1
7
Refreshing 5 745
Rock_Restart 4 510
LeadWill 4 679
APTX4869 5 374
WaterCop 5 607
ISAP 5 638
TLE 4 902
-
样例输出
-
APTX4869
-
来源
- SCU Programming Contest 2011
Preliminary
就是按照solved problem,(越大排前), penalties(越小排前),id(字典序排名)的规则排序:
代码:
#include <math.h>
#include <queue>
#include <deque>
#include <vector>
#include <stack>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) a>b?a:b
#define Min(a,b) a>b?b:a
#define mem(a,b) memset(a,b,sizeof(a))
int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
const double eps = 1e-6;
const double Pi = acos(-1.0);
static const int inf= ~0U>>2;
static const int maxn =110;
struct node
{
char id[25];
int num;
int time;
}
aa[maxn];
bool cmp(node a,node b)
{
return a.num!=b.num?a.num>b.num:a.time!=b.time?a.time<b.time:strcmp(a.id,b.id)<0;
}
int main()
{
int t,n,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0; i<n; i++)
scanf("%s%d%d",aa[i].id,&aa[i].num,&aa[i].time);
sort(aa,aa+n,cmp);
//printf("%d\n",aa[0].num);
printf("%s\n",aa[0].id);
}
return 0;
}
When you want to give up, think of why you persist until now!
NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~
标签:结构体 排序
原文地址:http://blog.csdn.net/u013050857/article/details/43919705