题目1130:日志排序
2014-01-27 20:52
260 查看
import java.io.IOException; import java.io.FileReader; import java.io.InputStreamReader; import java.io.BufferedReader; import java.util.Arrays; import java.util.Scanner; import java.lang.Comparable; import java.util.ArrayList; import java.util.List; import java.util.Collections; import java.util.Iterator; import java.util.Vector; class Log implements Comparable<Log> { public int year, month, day; public int hour, min, second, mm; public double cost; public String title; public int id; public Log(String s, int id) { String[] str = s.split("[ ]+"); title = str[0]; for (int i = 1; i < str.length; i++) { String tmp; if (i == 1) { tmp = str[i].substring(0, 4); year = Integer.parseInt(tmp); tmp = str[i].substring(5, 7); month = Integer.parseInt(tmp); tmp = str[i].substring(8); day = Integer.parseInt(tmp); } else if (i == 2) { tmp = str[i].substring(0, 2); hour = Integer.parseInt(tmp); tmp = str[i].substring(3, 5); min = Integer.parseInt(tmp); tmp = str[i].substring(6, 8); second = Integer.parseInt(tmp); tmp = str[i].substring(9); mm = Integer.parseInt(tmp); } else { tmp = str[i].substring(0, str[i].length() - 3); cost = Double.parseDouble(tmp); } } this.id = id; } public int compareTo(Log other) { if (cost < other.cost) return -1; else if (cost > other.cost) return 1; if (year != other.year) return year - other.year; if (month != other.month) return month - other.month; if (day != other.day) return day - other.day; if (hour != other.hour) return hour - other.hour; if (min != other.min) return min - other.min; if (second != other.second) return second - other.second; return mm - other.mm; } } class Main { public static final boolean DEBUG = false; public static void main(String[] args) throws IOException { BufferedReader cin; String s; int c; if (DEBUG) { cin = new BufferedReader(new FileReader("d:\\OJ\\uva_in.txt")); } else { cin = new BufferedReader(new InputStreamReader(System.in)); } List<Log> arr = new ArrayList<Log>(); c = 0; Vector<String> v = new Vector<String>(); while ((s = cin.readLine()) != null) { Log log = new Log(s, c); arr.add(log); v.add(s); c++; } //System.out.println(arr.size()); Collections.sort(arr); Iterator<Log> it = arr.iterator(); while (it.hasNext()) { Log log = it.next(); System.out.println(v.elementAt(log.id)); } } }
相关文章推荐
- 九度OJ 题目1130:日志排序
- 九度 oj 题目1130:日志排序
- 九度OJ 题目1130:日志排序
- 题目1130:日志排序
- 题目1130:日志排序
- 九度OJ 题目1130:日志排序
- 【九度】题目1130:日志排序
- 九度OJ 1130:日志排序 (排序)
- OJ_1130 日志排序
- 九度OJ 1130:日志排序 (排序)
- 题目4:EXCEL排序
- 4-题目1023:EXCEL排序
- 题目1023:EXCEL排序
- C 语言经典题目系列解决方案(9)-直接插入排序
- (第20讲)关于排序的各种算法的汇总的题目
- shell脚本处理日志的几个题目
- (日志,《算法导论》.6.2)堆排序,代码
- (日志,《算法导论》.7)快速排序,代码
- ACM题目:第一行输入n m,第二行输入一个数列,n为数列长度,m为要插入的值,排序后输出,m n为零时退出程序
- 各种排序相关题目的实现