HDOJ 2115 I Love This Game

来源:互联网 发布:淘宝买活体狗靠谱吗 编辑:程序博客网 时间:2024/05/21 04:00

题目链接:点击打开链接

题目大意:按照后面的时间排名,所用时间小的排前面,如果时间相等,按照名字的字典序排序。

此题我自己在做得第一次PE了,因为不晓得需要测试案例大于一组的时候要加一个换行

I Love This Game

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


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
10Iverson 17:19Bryant 07:03Nash 09:33Wade 07:03Davies 11:13Carter 14:28Jordan 29:34James 20:48Parker 24:49Kidd 26:460
 

Sample Output
Case #1Bryant 1Wade 1Nash 3Davies 4Carter 5Iverson 6James 7Parker 8
Kidd 9Jordan 10
具体代码实现:

package cn.hncu.acm;/* * 通过String类中的compareTo方法比较2个字符串的大小 */import java.util.Scanner;public class P2115 {public static void main(String[] args) {Scanner sc=new Scanner(System.in);int count=1;while(sc.hasNext()){int n=sc.nextInt();if(n==0){break;}if(count>1){//此处为PE关键点,本人就因为这里PE了一次System.out.println();}sc.nextLine();String a[]=new String[n];//用来装名字String b[]=new String[n];//用来装时间for(int i=0;i<n;i++){String str=sc.nextLine();String s[]=str.split(" ");a[i]=s[0];b[i]=s[1];}for(int i=0;i<n;i++){for(int j=i+1;j<n;j++){if(b[i].compareTo(b[j])>0){//比较时间,把名字时间的位置同时转换,得到的就是按时间顺序排列的2个数组String str=a[i];a[i]=a[j];a[j]=str;str=b[i];b[i]=b[j];b[j]=str;}if(b[i].compareTo(b[j])==0){if(a[i].compareTo(a[j])>0){//如果时间相同,则按名字的字典序排序String str=a[i];a[i]=a[j];a[j]=str;str=b[i];b[i]=b[j];b[j]=str;}}}}System.out.println("Case #"+count);count++;System.out.println(a[0]+" 1");//先输出第一个for(int i=1;i<n;i++){if(b[i].equals(b[i-1])){//如果这个时间跟上一个时间相同,则输出的序号跟上个位置序号相同System.out.println(a[i]+" "+i);}else{//否则输出该位置的本来序号System.out.println(a[i]+" "+(i+1));}}}}}