题目1130:日志排序

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));
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值