参考代码:
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二级辅导-计负均正 (C语言代码)浏览:652 |
C二级辅导-阶乘数列 (C语言代码)浏览:736 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:631 |
简单的a+b (C语言代码)浏览:661 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:821 |
字符逆序 (C语言代码)浏览:506 |
printf基础练习2 (C语言代码)浏览:547 |
1250题解浏览:603 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:622 |
求圆的面积 (C++代码)浮点数有误差!!!浏览:724 |