[恢]hdu 2115

2011-12-15 14:45:28

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2115

题意:nba技巧赛,输入人名,分钟,秒钟。按时间少到多排序,并输出rank。

mark:PE一次,每组case之间空一行。

代码:

# include <stdio.h>
# include <stdlib.h>
# include <string.h>


typedef struct NODE{
char name[50] ;
int mm, ss ;
}NODE ;


NODE node[20] ;


int cmp(const void *a, const void *b)
{
NODE *p = (NODE*)a, *q = (NODE*)b ;
int t1 = p->mm * 60 + p->ss ;
int t2 = q->mm * 60 + q->ss ;
if (t1 != t2) return t1- t2 ;
return strcmp (p->name, q->name) ;
}


int main ()
{
int n, rank, i, nCase = 1 ;
while (~scanf ("%d", &n))
{
if (n == 0) break ;
for (i = 0 ; i < n ; i++)
scanf ("%s %d:%d%*c", node[i].name, &(node[i].mm), &(node[i].ss)) ;
qsort (node, n, sizeof(NODE), cmp) ;
if (nCase != 1) printf ("\n") ;
printf ("Case #%d\n", nCase++) ;
for (i = 0 ; i < n ; i++)
{
if (i == 0) rank = 1 ;
else if (node[i].mm * 60 + node[i].ss ==
node[i-1].mm * 60 + node[i-1].ss)
rank = rank ;
else rank = i+1 ;
printf ("%s %d\n", node[i].name, rank) ;
}
}
return 0 ;
}



posted @ 2012-01-06 16:01  Seraph2012  阅读(154)  评论(0编辑  收藏  举报