NYOJ 707 A Simple Problem(結構體排序) 睡前一水~~,nyoj707

來源:互聯網
上載者:User

NYOJ 707 A Simple Problem(結構體排序) 睡前一水~~,nyoj707

連結: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.
範例輸入
17Refreshing 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!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.