首页 > 代码库 > hdu2115
hdu2115
I Love This Game
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7987 Accepted Submission(s): 2735
Problem Description
Do you like playing basketball ? If you are , you may know the NBA Skills Challenge . It is the content of the basketball skills . It include several parts , such as passing , shooting , and so on. After completion of the content , the player who takes the shortest time will be the winner . Now give you their names and the time of finishing the competition , your task is to give out the rank of them ; please output their name and the rank, if they have the same time , the rank of them will be the same ,but you should output their names in lexicographic order.You may assume the names of the players are unique.
Is it a very simple problem for you? Please accept it in ten minutes.
Is it a very simple problem for you? Please accept it in ten minutes.
Input
This problem contains multiple test cases! Ease test case contain a n(1<=n<=10) shows the number of players,then n lines will be given. Each line will contain the name of player and the time(mm:ss) of their finish.The end of the input will be indicated by an integer value of zero.
Output
The output format is shown as sample below.
Please output the rank of all players, the output format is shown as sample below;
Output a blank line between two cases.
Please output the rank of all players, the output format is shown as sample below;
Output a blank line between two cases.
Sample Input
10
Iverson 17:19
Bryant 07:03
Nash 09:33
Wade 07:03
Davies 11:13
Carter 14:28
Jordan 29:34
James 20:48
Parker 24:49
Kidd 26:46
0
Sample Output
Case #1
Bryant 1
Wade 1
Nash 3
Davies 4
Carter 5
Iverson 6
James 7
Parker 8
Kidd 9
Jordan 10
1 #include<cstdio>
2 #include<iostream>
3 #include<string>
4 #include<algorithm>
5 #include<cstring>
6 #include<string>
7 using namespace std;
8 struct node
9 {
10 string name;
11 int a,b;
12 char c;
13 int flag;
14 }g[15];
15 bool cmp(struct node x,struct node y)
16 {
17 if(x.a==y.a&&x.b==y.b)
18 {
19 return x.name<y.name;
20 }
21 if(x.a==y.a)
22 return x.b<y.b;
23 return x.a<y.a;
24 }
25 int main()
26 {
27 long long n,t,i;
28 int ans=1;
29 while(cin>>n&&n)
30 {
31 for(i=1;i<=n;i++)
32 {
33 getchar();
34 cin>>g[i].name;
35 cin>>g[i].a;
36 cin>>g[i].c;
37 cin>>g[i].b;
38 g[i].flag=0;
39 }
40 if(ans!=1)
41 cout<<endl;
42 cout<<"Case #"<<ans++<<endl;
43 sort(g+1,g+n+1,cmp);
44 sort(g+1,g+n+1,cmp);
45 for(i=1;i<=n;i++)
46 {
47 if(g[i].a==g[i-1].a&&g[i].b==g[i-1].b)
48 {
49 for(int k=i;k>=0;k--)
50 {
51 if(g[i].a!=g[k].a||(g[i].a==g[k].a&&g[i].b!=g[k].b))
52 {
53 cout<<g[i].name<<‘ ‘<<k+1<<endl;
54 break;
55 }
56 }
57 }
58 else
59 cout<<g[i].name<<‘ ‘<<i<<endl;
60 }
61 }
62 }
hdu2115
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。