-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ07050_SapXepMatHang.java
51 lines (42 loc) · 1.28 KB
/
J07050_SapXepMatHang.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
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
class matHang implements Comparable<matHang> {
public String mh, th, nh;
public double gm, gb, ln;
public matHang(int id, String th, String nh, double gm, double gb) {
if (id < 10) {
this.mh = "MH0" + String.valueOf(id);
} else {
this.mh = "MH" + String.valueOf(id);
}
this.th = th;
this.nh = nh;
this.gb = gb;
this.gm = gm;
this.ln = gb - gm;
}
@Override
public int compareTo(matHang t) {
return this.ln > t.ln ? -1 : 1;
}
public void display() {
System.out.printf("%s %s %s %.2f\n", mh, th, nh, ln);
}
}
public class J07050_SapXepMatHang {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("MATHANG.in"));
int n = sc.nextInt();
ArrayList<matHang> a = new ArrayList<>();
for (int i = 1; i <= n; i++) {
sc.nextLine();
a.add(new matHang(i, sc.nextLine(), sc.nextLine(), sc.nextDouble(), sc.nextDouble()));
}
Collections.sort(a);
for (matHang mh : a) {
mh.display();
}
}
}