NYOJ 707 A Simple Problem (structured sorting) water before going to bed ~~, Nyoj707

Source: Internet
Author: User

NYOJ 707 A Simple Problem (structured sorting) water before going to bed ~~, Nyoj707

Link: click here

Question:

A Simple Problem time limit: 3000 MS | memory limit: 65535 KB difficulty: 2
Description
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 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.
Input
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 [2, 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.
Output
For each test case, output one line with an string indicating the champion.
Sample Input
17Refreshing 5 745 Rock_Restart 4 510 LeadWill 4 679 APTX4869 5 374 WaterCop 5 607 ISAP 5 638 TLE 4 902 
Sample output
APTX4869
Source
SCU Programming Contest 2011 Preliminary
It is sorted by the solved problem, (before the larger row), penalties (before the smaller row), and id (lexicographically ranking) Rules:

Code:

 #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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.