HDU 2115 I Love This Game(结构体排序 or pair)
2016-05-15 00:13
411 查看
I Love This Game
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7163 Accepted Submission(s): 2451
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
Case #1 Bryant 1 Wade 1 Nash 3 Davies 4 Carter 5 Iverson 6 James 7 Parker 8 Kidd 9 Jordan 10
[align=left]Author[/align]
為傑沉倫
[align=left]Source[/align]
HDU 2007-10 Programming Contest_WarmUp
题解:结构体 or pair<string,string>e[12].
AC代码:
#include<iostream> #include<memory.h> #include<cstdlib> #include<cstdio> #include<cmath> #include<cstring> #include<string> #include<cstdlib> #include<iomanip> #include<vector> #include<list> #include<map> #include<queue> #include<algorithm> typedef long long LL; using namespace std; //数学公式:1^3+2^3+3^3+....n^3=[n(n+1)/2]^2 struct node { char name[10]; int m,s; }p[11]; bool cmp(node a,node b) { if(a.m==b.m&&a.s==b.s) return strcmp(a.name,b.name)<0; //按字典序从小到大 else if(a.m==b.m) return a.s<b.s; //从小到大 return a.m<b.m; } int main() { bool ok=0; int i,j,n,ca=1,r,sum; while(~scanf("%d",&n),n) { if(ok) printf("\n"); ok=1; for(i=0;i<n;i++) { scanf("%s %d:%d",p[i].name,&p[i].m,&p[i].s); } r=1,sum=1; sort(p,p+n,cmp); printf("Case #%d\n",ca++); for(i=0;i<n;i++) { if(i!=0&&(p[i].m!=p[i-1].m||p[i].s!=p[i-1].s)) r=sum; //r为名次 printf("%s %d\n",p[i].name,r); sum++; } } return 0; }
AC:pair
#include <iostream> #include <utility> #include <algorithm> #include <cstring> #include <cmath> using namespace std; //#define LOCAL int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif int T=0,n,mc[12]; string str1,str2; pair<string,string> e[12]; while(cin>>n,n) { if(T) cout<<endl; cout<<"Case #"<<++T<<endl; if(T>1) cout<<endl; for(int i=0;i<n;++i) { cin>>str1>>str2; e[i]=make_pair(str2,str1); } sort(e,e+n); mc[0]=1; for(int i=1;i<n;++i) if(e[i].first==e[i-1].first) mc[i]=mc[i-1]; else mc[i]=i+1; for(int i=0;i<n;++i) cout<<e[i].second<<' '<<mc[i]<<endl; } return 0; }
相关文章推荐
- HDU 5228-ZCC loves straight flush
- Domain Transform for Edge-Aware Image and Video Processing - 论文阅读
- At least one JAR was scanned for TLDs yet contained no TLDs 解决办法
- 服务器TIME_WAIT和CLOSE_WAIT详解和解决办法
- hdoj-1789-Doing Homework again
- 11. Container With Most Water
- hdu_1532_Drainage Ditches
- uva10651 Pebble Solitaire(记忆化搜索)
- 1106. Lowest Price in Supply Chain (25)【树+深搜】——PAT (Advanced Level) Practise
- 1090. Highest Price in Supply Chain (25)【树】——PAT (Advanced Level) Practise
- 无法解析的外部符号WinMain@16
- 谷歌黑科技:联机版人工智能系统
- 172. Factorial Trailing Zeroes
- Contains Duplicate II
- sleep方法和wait方法的区别
- VS中多个main的问题
- leetcode-Container With Most Water
- trait
- rabbitmq 集群 ha负载 Consumer raised exception, processing can restart if the connection factory
- 2014山东省第五届ACM省赛 angry_birds_again_and_again