点击打开杭电1177
10 1 2 3 6 2 02:45:17 2 02:49:01 2 03:17:58 2 03:21:29 4 07:55:48 3 04:25:42 3 06:57:39 2 02:05:02 2 02:16:45 2 02:41:37 0 0 0 0 0
Accepted today? I've got a silver medal :)
思路:简单的结构体排序,java里用类代替结构体就行了,很简单。
package xjj; import java.util.Scanner; public class P1177{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int g=sc.nextInt(); int s=sc.nextInt(); int c=sc.nextInt(); int m=sc.nextInt(); if(n+g+s+c+m==0){ return ; } Body[] body=new Body[n]; for(int i=0;i<n;i++){ int num=sc.nextInt(); String time=sc.next(); body[i]=new Body(num,time); } body[m-1].isMy=true; sort(body); int i; for(i=0;i<n;i++){ //System.out.println(body[i].num+" "+body[i].time+" "+body[i].isMy); if(body[i].isMy){ break; } } i+=1; if(i<=g){ System.out.println("Accepted today? I've got a golden medal :)"); }else if(i<=g+s){ System.out.println("Accepted today? I've got a silver medal :)"); }else if(i<=g+s+c){ System.out.println("Accepted today? I've got a copper medal :)"); }else{ System.out.println("Accepted today? I've got an honor mentioned :)"); } } } private static void sort(Body[] body) { Body temp=new Body(); for(int i=0;i<body.length-1;i++){ for(int j=0;j<body.length-1-i;j++){ if(body[j].num<body[j+1].num){ temp=body[j]; body[j]=body[j+1]; body[j+1]=temp; }else if(body[j].num==body[j+1].num){ if(body[j].timer>body[j+1].timer){ temp=body[j]; body[j]=body[j+1]; body[j+1]=temp; } } } } } } class Body { public int num; public String time; public int timer; boolean isMy=false; public Body(int num,String time){ this.num=num; this.time=time; func(time); } public Body(){ } private void func(String time2) { String[] str=time2.split(":"); int h=Integer.parseInt(str[0]); int m=Integer.parseInt(str[1]); int s=Integer.parseInt(str[2]); this.timer=h*60*60+m*60+s; } }