-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ07051_TinhTienPhong.java
133 lines (119 loc) · 3.93 KB
/
J07051_TinhTienPhong.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//B21DCCN441
import java.util.*;
import java.math.*;
import java.io.*;
class Khach {
public String mkh, tkh, mp, in, out;
public int snlt, dg, pp, tt;
public Khach(int id, String name, String room, String dayin, String dayout, int pp) {
if (id < 10) {
mkh = "KH0" + String.valueOf(id);
} else {
mkh = "KH" + String.valueOf(id);
}
this.tkh = Title(name);
this.mp = room;
this.in = TitleDate(dayin);
this.out = TitleDate(dayout);
this.snlt = dis(this.in, this.out);
this.pp = pp;
this.dg = 25;
if (room.subSequence(0, 1).equals("2")) {
this.dg = 34;
} else if (room.subSequence(0, 1).equals("3")) {
this.dg = 50;
} else if (room.subSequence(0, 1).equals("4")) {
this.dg = 80;
}
this.tt = this.dg * this.snlt + this.pp;
}
public String Title(String name) {
String ans = "";
StringTokenizer ss = new StringTokenizer(name.toLowerCase());
while (ss.hasMoreTokens()) {
String s = ss.nextToken();
ans += s.toUpperCase().charAt(0) + s.substring(1) + " ";
}
return ans.substring(0, ans.length() - 1);
}
public String TitleDate(String day) {
String ans = day;
if (ans.charAt(1) == '/') {
ans = "0" + ans;
}
if (ans.charAt(4) == '/') {
ans = ans.substring(0, 3) + "0" + ans.substring(3);
}
return ans;
}
public int dayOfYear(int y) {
if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) {
return 366;
} else {
return 365;
}
}
public int dayOfMonth(int m, int y) {
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
return 31;
} else if (m != 2) {
return 30;
} else if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) {
return 29;
} else {
return 28;
}
}
public int dayth(int d, int m, int y) {
if (m == 1) {
return d;
}
int day = 0;
for (int i = 1; i < m; i++) {
day += dayOfMonth(i, y);
}
return day + d;
}
public int dis(String a, String b) {
int d1 = Integer.valueOf(a.substring(0, 2));
int d2 = Integer.valueOf(b.substring(0, 2));
int m1 = Integer.valueOf(a.substring(3, 5));
int m2 = Integer.valueOf(b.substring(3, 5));
int y1 = Integer.valueOf(a.substring(6, 10));
int y2 = Integer.valueOf(b.substring(6, 10));
int distance = 0;
if (y1 != y2) {
for (int i = y1 + 1; i < y2; i++) {
distance += dayOfYear(i);
}
distance += dayth(d2, m2, y2);
distance += dayOfYear(y1) - dayth(d1, m1, y1);
return distance;
}
return dayth(d2, m2, y2) - dayth(d1, m1, y1) + 1;
}
@Override
public String toString() {
return this.mkh + " " + this.tkh + " " + this.mp + " " + this.snlt + " " + this.tt;
}
}
public class J07051_TinhTienPhong {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("KHACHHANG.in"));
int n = sc.nextInt();
ArrayList<Khach> a = new ArrayList<>();
for (int i = 1; i <= n; i++) {
sc.nextLine();
a.add(new Khach(i, sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextInt()));
}
Collections.sort(a, new Comparator<Khach>() {
@Override
public int compare(Khach t, Khach t1) {
return t.tt > t1.tt ? -1 : 1;
}
});
for (Khach k : a) {
System.out.println(k);
}
}
}