-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloaiphong.java
More file actions
45 lines (37 loc) · 1.05 KB
/
Copy pathloaiphong.java
File metadata and controls
45 lines (37 loc) · 1.05 KB
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
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.io.IOException;
class LoaiPhong implements Comparable<LoaiPhong> {
private String line, name;
public LoaiPhong(String line) {
this.line = line;
this.name = line.trim().split("\\s+")[1];
}
public String getName() {
return name;
}
@Override
public String toString() {
return line;
}
@Override
public int compareTo(LoaiPhong o) {
return name.compareTo(o.getName());
}
}
public class loaiphong {
public static void main(String[] args) throws IOException {
ArrayList<LoaiPhong> ds = new ArrayList<>();
Scanner in = new Scanner(new File("PHONG.in"));
int n = Integer.parseInt(in.nextLine());
while (n-- > 0) {
ds.add(new LoaiPhong(in.nextLine()));
}
Collections.sort(ds);
for (LoaiPhong tmp : ds) {
System.out.println(tmp);
}
}
}