码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2115

时间:2015-01-30 22:53:51      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:acm算法   amp   c   math.h   printf   

I Love This Game

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


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
 

Author
為傑沉倫
 

Source
水题。
就是时间小的排前面,时间相同的排名一样,且字典序在前的先输出并且空掉以个排名。比如2个第一名,都是1. 就没有排名2 的了。还有就是空行的输出,第二次输入一个数后就要换行了。
注意以上几点,就能AC了。
附上简陋的代码
#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;
}

 
 
 

HDU 2115

标签:acm算法   amp   c   math.h   printf   

原文地址:http://blog.csdn.net/sky_miange/article/details/43307897

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!