-
Notifications
You must be signed in to change notification settings - Fork 0
/
J1006.java
62 lines (49 loc) · 1.52 KB
/
J1006.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
class People implements Comparable {
public String id;
public Date begin, end;
public People(String info) throws Exception {
String[] attr = info.split(" ");
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
this.id = attr[0];
this.begin = format.parse(attr[1]);
this.end = format.parse(attr[2]);
}
@Override
public int compareTo(Object o) {
People p = (People)o;
return begin.before(p.begin) ? -1 : 1;
}
@Override
public String toString() {
return this.id + " " + begin.toString() + " " + end.toString();
}
}
public class J1006 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
List<People> l = new ArrayList<>();
int n = sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String s = sc.nextLine();
l.add(new People(s));
}
Collections.sort(l);
Date last = l.get(0).end;
String ans = l.get(0).id;
for (People p : l) {
if (p.end.after(last)) {
last = p.end;
ans = p.id;
}
}
System.out.println(l.get(0).id + " " + ans);
sc.close();
}
}