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));
}
}
}
题目1130:日志排序
最新推荐文章于 2022-06-10 12:33:04 发布