参考代码:
import java.util.Collections; import java.util.Scanner; import java.util.Vector; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Vector<Date> dates = new Vector<Date>(); while(scanner.hasNext()) { dates.add(new Date(scanner.nextLine())); } Collections.sort(dates); for(Date t: dates) System.out.println(t); } } class Date implements Comparable<Object> { private int year, month, day; private String original; Date(String s) { original = s; String []ss = s.split("/"); day = Integer.parseInt(ss[1]); month = Integer.parseInt(ss[0]); year = Integer.parseInt(ss[2]); } public int compareTo(Object o) { Date oo = (Date)o; if(this.year > oo.year) return 1; else if(this.year == oo.year) { if(this.month > oo.month) return 1; else if(this.month == oo.month) { if(this.day > oo.day) return 1; else if(this.day == oo.day) return 0; } } return - 1; } public String toString() { return original; } }
0.0分
5 人评分
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:654 |
简单的a+b (C语言代码)浏览:573 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:468 |
最小公倍数 (C语言代码)浏览:1026 |
水仙花 (C语言代码)浏览:1047 |
文科生的悲哀 (C语言代码)浏览:1398 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:463 |
神奇的fans (C语言代码)浏览:977 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:839 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:500 |