当前位置: 代码迷 >> 综合 >> HDOJ 2115 I Love This Game
  详细解决方案

HDOJ 2115 I Love This Game

热度:40   发布时间:2023-10-21 18:53:15.0

HDACM 2115

细心

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);int k = 1;while(sc.hasNext()){int n = sc.nextInt();if (n==0) {break;}Student3[] s = new Student3[n];for (int i = 0; i < n; i++) {s[i] = new Student3();s[i].name = sc.next();String time = sc.next();String[] split = time.split(':'+"");s[i].mm = Integer.parseInt(split[0]);s[i].ss = Integer.parseInt(split[1]);}Arrays.sort(s,new Comparator<Student3>() {@Overridepublic int compare(Student3 o1, Student3 o2) {if (o1.mm<o2.mm) {return -1;}if (o1.mm>o2.mm) {return 1;}if (o1.mm==o2.mm) {if (o1.ss<o2.ss) {return -1;}if (o1.ss>o2.ss) {return 1;}if (o1.ss == o2.ss) {if (o1.name.compareTo(o2.name)>0) {return 1;}else{return 0;}}}return 0;}});if (k>1) {System.out.println();}System.out.println("Case #"+k++);int mm = s[0].mm;int ss = s[0].ss;int j = 1;System.out.println(s[0].name+" "+j);for (int i = 1; i < s.length; i++) {if (s[i].mm == mm&&s[i].ss == ss) {System.out.println(s[i].name+" "+j);continue;}j = i+1;mm =s[i].mm;ss =s[i].ss;    System.out.println(s[i].name+" "+j);}}sc.close();}
}
class Student3{String name;int mm;int ss;
}
  相关解决方案