-
Notifications
You must be signed in to change notification settings - Fork 1
/
DanhSachCaThi.java
60 lines (55 loc) · 1.82 KB
/
DanhSachCaThi.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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package NewNhanVien;
import java.util.*;
import java.io.*;
/**
*
* @author Administrator
*/
class CaThi implements Comparable<CaThi>{
private String id;
private String date;
private String time;
private String idRoom;
public CaThi(int id, String date, String time, String idRoom) {
this.id = "C" + String.format("%03d", id);
this.date = date;
this.time = time;
this.idRoom = idRoom;
}
@Override
public int compareTo(CaThi b){
String cmp1 = this.date.substring(6) + this.date.substring(3, 5)
+ this.date.substring(0, 2) + this.time;
String cmp2 = b.date.substring(6) + b.date.substring(3, 5)
+ b.date.substring(0, 2) + b.time;
if(!cmp1.equals(cmp2))
return cmp1.compareTo(cmp2);
return this.id.compareTo(b.id);
}
@Override
public String toString() {
return this.id + " " + this.date + " " + this.time + " " + this.idRoom;
}
}
public class DanhSachCaThi {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("CATHI.in"));
int n = sc.nextInt();
ArrayList<CaThi> a = new ArrayList<>();
sc.nextLine();
for(int i=1; i<=n; i++){
String date = sc.nextLine();
String time = sc.nextLine();
String idRoom = sc.nextLine();
a.add(new CaThi(i, date, time, idRoom));
}
Collections.sort(a);
for(CaThi i : a){
System.out.println(i);
}
}
}