HDU 2115 -I Love This Game
生活随笔
收集整理的這篇文章主要介紹了
HDU 2115 -I Love This Game
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>//包含qsort函數的頭文件
4 struct node
5 {
6 char name[20],time[6];
7 int t;//時間
8 int rank;//排名
9 }p[11];
10 int cmp(const void *a,const void *b)
11 {
12 struct node *c=(struct node *)a;
13 struct node *d=(struct node *)b;
14 if(c->t!=d->t)
15 {return c->t-d->t;}//時間比較
16 else
17 {return strcmp(c->name,d->name);}//名字字典排序
18 }
19 int main()
20 {
21 int n,i,j,count,ranklist,flag,m;
22 count=0;
23 m=0;
24 while(scanf("%d",&n)!=EOF)
25 {
26 if(n==0)
27 {break;}
28 if(m!=0)
29 {printf("\n");}
30 m++;
31 for(i=0;i<n;i++)
32 {
33 getchar();
34 scanf("%s%s",p[i].name,p[i].time);
35 p[i].t=((p[i].time[0]-'0')*10+(p[i].time[1]-'0'))*60+(p[i].time[3]-'0')*10+(p[i].time[4]-'0');
36 }
37 qsort(p,n,sizeof(p[0]),cmp);
38
39 printf("Case #%d\n",++count);
40 ranklist=1;
41 for(i=0;i<n;i++)//時間相同的運動員計數
42 {
43 flag=i;// 標記時間相同的運動員的起始下標;
44 while(p[i].t==p[i+1].t)
45 {i++;}
46 for(j=flag;j<=i;j++)
47 p[j].rank=ranklist;//給排名賦值0
48 ranklist+=j-flag;
49 }
50 for(i=0;i<n;i++)
51 {
52 printf("%s %d\n",p[i].name,p[i].rank);
53 }
54 }
55 return 0;
56 }
57
轉載于:https://www.cnblogs.com/mycapple/archive/2012/08/02/2620324.html
總結
以上是生活随笔為你收集整理的HDU 2115 -I Love This Game的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2012 Multi-Universit
- 下一篇: 【JAVASCRIPT】无刷新评论