-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMain.java
107 lines (95 loc) · 1.96 KB
/
Main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package basicLevel1028;
// 测试点4运行超时
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
People max = new People("", "2014/09/06");
People min = new People("", "1814/09/06");
int isValid = 0;
for (int i = 0; i < n; i++) {
People p = new People(in.next(), in.next());
if (p.isVaild) {
max = max.compareTo(p) > 0 ? max : p;
min = min.compareTo(p) < 0 ? min : p;
isValid++;
}
}
in.close();
if (isValid == 0) {
System.out.println(0);
} else {
System.out.println(isValid + " " + max.name + " " + min.name);
}
}
}
class People implements Comparable<People>{
String name;
int year;
int month;
int day;
boolean isVaild;
public People(String name, String date) {
this.name = name;
String[] d = date.split("/");
year = Integer.parseInt(d[0]);
month = Integer.parseInt(d[1]);
day = Integer.parseInt(d[2]);
if (year > 2014) {
isVaild = false;
} else if (year == 2014) {
if (month > 9) {
isVaild = false;
} else if (month == 9) {
if (day > 6) {
isVaild = false;
} else {
isVaild = true;
}
} else {
isVaild = true;
}
} else if (year < 2214 && year > 1814) {
isVaild = true;
} else if (year < 1814) {
isVaild = false;
} else if (year == 1814) {
if (month < 9) {
isVaild = false;
} else if (month == 9) {
if (day >= 6) {
isVaild = true;
} else {
isVaild = false;
}
} else {
isVaild = true;
}
} else {
isVaild = false;
}
}
@Override
public int compareTo(People o) {
if (this.year > o.year) {
return -1;
} else if (this.year < o.year) {
return 1;
} else {
if (this.month > o.month) {
return -1;
} else if (this.month < o.month) {
return 1;
} else {
if (this.day < o.day) {
return 1;
} else if (this.day > o.day) {
return -1;
} else {
return 0;
}
}
}
}
}