-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ05082_DanhSachKhachHang.java
80 lines (72 loc) · 2.38 KB
/
J05082_DanhSachKhachHang.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
//B21DCCN441
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;
class KhachHang {
public String id, name, sex, birth, address;
public int d, m, y;
public KhachHang(int i, String ten, String gioiTinh, String ngaySinh, String diaChi) {
this.id = "KH" + i;
if (i < 10) {
this.id = "KH00" + i;
} else if (i < 100) {
this.id = "KH0" + i;
}
this.address = diaChi;
this.sex = gioiTinh;
this.name = titleName(ten.toLowerCase());
this.birth = titleDate(ngaySinh);
this.d = Integer.valueOf(birth.substring(0, 2));
this.m = Integer.valueOf(birth.substring(3, 5));
this.y = Integer.valueOf(birth.substring(6, 10));
}
public String titleDate(String s) {
if (s.charAt(1) == '/') {
s = "0" + s;
}
if (s.charAt(4) == '/') {
s = s.substring(0, 3) + "0" + s.substring(3);
}
return s;
}
public String titleName(String name) {
StringTokenizer ss = new StringTokenizer(name);
String ans = "";
while (ss.hasMoreTokens()) {
String s = ss.nextToken();
char x = (char) (s.charAt(0) - 32);
ans += x + s.substring(1) + " ";
}
return ans.substring(0, ans.length() - 1);
}
@Override
public String toString() {
return this.id + " " + this.name + " " + this.sex + " " + this.address + " " + this.birth;
}
}
public class J05082_DanhSachKhachHang {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
ArrayList<KhachHang> a = new ArrayList<>();
for (int i = 1; i <= n; i++) {
a.add(new KhachHang(i, sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine()));
}
Collections.sort(a, new Comparator<KhachHang>() {
@Override
public int compare(KhachHang t, KhachHang t1) {
if (t.y != t1.y) {
return t.y - t1.y;
} else if (t.m != t1.m) {
return t.m - t1.m;
}
return t.d - t1.d;
}
});
for (KhachHang kh : a) {
System.out.println(kh);
}
}
}