首页 文章详情

hdu 2115 I Love This Game

ACM比赛整理 | 104 2022-12-17 16:19 0 0 0
UniSMS (合一短信)

 I Love This Game


Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10045    Accepted Submission(s): 3422

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.

 


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.

 


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




我爱这个游戏


问题描述


你喜欢打篮球吗?如果你是,你可能知道NBA技能挑战。它是篮球技术的内容。它包括传球、投篮等几个部分。完成内容后,用时最短的玩家将获胜。现在给你他们的名字和完成比赛的时间,你的任务是给他们的排名;请输出他们的名字和等级,如果他们有相同的时间,他们的等级将是相同的,但你应该输出他们的名字在字典的顺序。你可以假设球员的名字是独一无二的。

这个问题对你来说很简单吗?请在十分钟内接受。


输入

这个问题包含多个测试用例!轻松测试用例包含n(1<=n<=10)显示玩家的数量,然后给出n行。每一行将包含运动员的名字和他们完成比赛的时间(mm:ss)。输入的末尾将由一个零的整数值表示。


输出

输出格式如下所示。

请输出所有选手的排名,输出格式如下图所示;

在两种情况之间输出空行。


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



解题思路:

就是时间小的排前面,时间相同的排名一样,且字典序在前的先输出并且空掉以个排名。比如2个第一名,都是1. 就没有排名2 的了。还有就是空行的输出,第二次输入一个数后就要换行了。


代码:

#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
struct node
{
char name[6666];
char time[6666];
};
node f[6666];
bool cmp(node a,node b)
{
if(a.time!=b.time)
return strcmp(a.time,b.time)<0;
else
return strcmp(a.name,b.name)<0;
}
int main()
{
int n,i,j;
int c=0;
int t=1;
while(scanf("%d",&n)&&n)
{
if(t>1)
printf("\n");
for(i=1;i<=n;i++)
scanf("%s%s",f[i].name,f[i].time);
sort(f+1,f+n+1,cmp);
printf("Case #%d\n",++c);
for(i=1;i<=n;i++)
{
printf("%s %d\n",f[i].name,i);
if(strcmp(f[i].time,f[i+1].time)==0)
{
printf("%s %d\n",f[i+1].name,i);
i++;
}
}
t++;
}
return 0;
}


good-icon 0
favorite-icon 0
收藏
回复数量: 0
    暂无评论~~
    Ctrl+Enter