-
Notifications
You must be signed in to change notification settings - Fork 1
/
CauLacBoBongDa2.java
113 lines (99 loc) · 2.83 KB
/
CauLacBoBongDa2.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
/*
* 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.*;
/**
*
* @author Administrator
*/
class CLB{
private String id;
private String ten;
private int cost;
public CLB(String id, String ten, int cost) {
this.id = id;
this.ten = ten;
this.cost = cost;
}
public String getId() {
return id;
}
public String getTen() {
return ten;
}
public int getCost() {
return cost;
}
}
class TranDau implements Comparable<TranDau>{
private String id;
private int soLuong;
private int tong;
private String tenDoi;
public TranDau(String id, int soLuong) {
this.id = id;
this.soLuong = soLuong;
}
public String getId() {
return id;
}
public int getSoLuong() {
return soLuong;
}
public void setTong(int tong) {
this.tong = tong;
}
public void setTenDoi(String tenDoi) {
this.tenDoi = tenDoi;
}
@Override
public int compareTo(TranDau b){
if(this.tong != b.tong){
return -Integer.compare(this.tong, b.tong);
}
return this.tenDoi.compareTo(b.tenDoi);
}
@Override
public String toString() {
return this.id + " " + this.tenDoi + " " + this.tong;
}
}
public class CauLacBoBongDa2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<CLB> aCLB = new ArrayList<>();
ArrayList<TranDau> aTranDau = new ArrayList<>();
for(int i=0; i<n; i++){
sc.nextLine();
String id = sc.nextLine();
String ten = sc.nextLine();
int cost = sc.nextInt();
aCLB.add(new CLB(id, ten, cost));
}
int m = sc.nextInt();
for(int i=0; i<m; i++){
sc.nextLine();
String id = sc.next();
int soLuong = sc.nextInt();
aTranDau.add(new TranDau(id, soLuong));
}
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(aTranDau.get(i).getId().substring(1, 3).equalsIgnoreCase(aCLB.get(j).getId())){
aTranDau.get(i).setTenDoi(aCLB.get(j).getTen());
aTranDau.get(i).setTong(
aTranDau.get(i).getSoLuong() * aCLB.get(j).getCost()
);
break;
}
}
}
Collections.sort(aTranDau);
for(TranDau i : aTranDau){
System.out.println(i);
}
}
}