I Love This Game hdu 2115
2014-03-06 15:04
387 查看
I Love This Game
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5248 Accepted Submission(s): 1811
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
HDU 2007-10 Programming Contest_WarmUp
Recommend
威士忌 | We have carefully selected several similar problems for you: 2117 2116 2118 2120 2143
#include<iostream> #include<cstdio> #include<string.h> #include<algorithm> using namespace std; struct node { char a[100]; int d;//data int e;//еецШ }unit[20]; struct nop { int c;//╪гйЩ╬щ int d;//еепР }ua[20]; int cmd1(nop a,nop b) { return a.c<b.c; } int cmd2(node a,node b) { return a.e<b.e; if(a.e==b.e) { int h=strcmp(a.a,b.a); return h<0; } } int main() { int i,j,k,n; int T=1; int ap[20]; // while(scanf("%d",&n)!=EOF) scanf("%d",&n); int c,h; if(n!=0) { // int e=100000000; for(i=0;i<n;i++) { scanf("%s %d:%d",&unit[i].a,&c,&h); unit[i].d=c*100+h; ua[i].c=unit[i].d; // printf("fdfsdfds%d\n",unit[i].d); //printf("%d\n",unit[i].d); //uia } //printf("fjdslfjsd\n"); sort(ua,ua+n,cmd1); /* for(i=0;i<n;i++) { printf("%d\n",ua[i].c); }*/ ua[0].d=1; int t=1; for(i=1;i<n;i++) { if(ua[i].c==ua[i-1].c) { ua[i].d=ua[i-1].d; t++; } else { t++; ua[i].d=t; } } /* for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(ua[i].c==ua[j].c) { ua[j].d=ua[i].d; t++; } else { t++; ua[j].d=t; break; } } }*/ /* for(i=0;i<n;i++) { printf("%d %d\n",ua[i].c,ua[i].d); }*/ for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(unit[i].d==ua[j].c) { unit[i].e=ua[j].d; break; } } } sort(unit,unit+n,cmd2); printf("Case #%d\n",T); //printf("fhsjkdfdsffdsfdsfdssdfs"); for(i=0;i<n;i++) { printf("%s %d\n",unit[i].a,unit[i].e); } //printf("fhdsjkfs"); //printf("\n"); } while(scanf("%d",&n)!=EOF) { int c,h; T++; if(n==0) break; // int e=100000000; for(i=0;i<n;i++) { scanf("%s %d:%d",&unit[i].a,&c,&h); unit[i].d=c*100+h; ua[i].c=unit[i].d; // printf("fdfsdfds%d\n",unit[i].d); //printf("%d\n",unit[i].d); //uia } //printf("fjdslfjsd\n"); sort(ua,ua+n,cmd1); /* for(i=0;i<n;i++) { printf("%d\n",ua[i].c); }*/ ua[0].d=1; int t=1; for(i=1;i<n;i++) { if(ua[i].c==ua[i-1].c) { ua[i].d=ua[i-1].d; t++; } else { t++; ua[i].d=t; } } /* for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(ua[i].c==ua[j].c) { ua[j].d=ua[i].d; t++; } else { t++; ua[j].d=t; break; } } }*/ /* for(i=0;i<n;i++) { printf("%d %d\n",ua[i].c,ua[i].d); }*/ for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(unit[i].d==ua[j].c) { unit[i].e=ua[j].d; break; } } } sort(unit,unit+n,cmd2); printf("\n"); printf("Case #%d\n",T); //printf("fhsjkdfdsffdsfdsfdssdfs"); for(i=0;i<n;i++) { printf("%s %d\n",unit[i].a,unit[i].e); } //printf("fhdsjkfs"); //printf("\n"); //T++; //printf("\n"); } return 0; }
上面是我的挫代码,下面是别人的简单代码
#include <map> #include <string> #include <iostream> #include <cstdio> #include <algorithm> using namespace std; class person { public: string name; int time; int rank; }; bool cmp(person a,person b) { if(a.time!=b.time) return a.time<b.time; else return a.name<b.name; } int main() { int testcase,cnt=1; int enterpos=0; while(cin>>testcase) { person manlist[100]; if(testcase==0) break; else { for(int i=0;i<testcase;i++) { string tmpname; int time=0,shi,fen; cin>>manlist[i].name; scanf("%d:%d",&shi,&fen); time=shi*60+fen; manlist[i].time=time; } sort(manlist,manlist+testcase,cmp); int rnklist=1; manlist[0].rank=rnklist; for(int i=1;i<testcase;i++) { if(manlist[i].time==manlist[i-1].time) { manlist[i].rank=manlist[i-1].rank; } else { manlist[i].rank=i+1; } } if(enterpos==1) cout<<endl; enterpos=1; cout<<"Case #"<<cnt<<endl; cnt++; for(int i=0;i<testcase;i++) { cout<<manlist[i].name<<" "<<manlist[i].rank<<endl; } } } return 0; }
相关文章推荐
- VBS ArrayList Class vbs中的数组类
- 大家看了就明白了css样式中类class与标识id选择符的区别小结
- C++ 关于STL中sort()对struct排序的方法
- 深入了解PHP类Class的概念
- C# Struct的内存布局问题解答
- PHP echo,print,printf,sprintf函数之间的区别与用法详解
- setAttribute 与 class冲突解决
- Javascript SHA-1:Secure Hash Algorithm
- javascript面向对象包装类Class封装类库剖析
- php printf输出格式使用说明
- PHP学习之输出字符串(echo,print,printf,print_r和var_dump)
- JavaScript更改class和id的方法
- 一篇入门的php Class 文章
- 深入C++中struct与class的区别分析
- php输出echo、print、print_r、printf、sprintf、var_dump的区别比较
- js中设置元素class的三种方法小结
- C语言printf详细解析
- 浅析c与c++中struct的区别
- c++中typename和class的区别介绍