-
Notifications
You must be signed in to change notification settings - Fork 1
/
DanhSachGiangVienTheoBoMon.java
67 lines (61 loc) · 1.74 KB
/
DanhSachGiangVienTheoBoMon.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
/*
* 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 codeptit;
import java.util.*;
import java.math.*;
/**
*
* @author Administrator
*/
class GiangVien{
private String id;
private String ten;
private String khoa;
public GiangVien(int id, String ten, String khoa) {
this.id = "GV" + String.format("%02d", id);
this.ten = ten;
this.khoa = khoa;
}
public String getKhoa() {
return khoa;
}
@Override
public String toString() {
return this.id + " " + this.ten + " " + this.khoa;
}
}
public class DanhSachGiangVienTheoBoMon {
public static String conv(String s){
String res = "";
StringTokenizer st = new StringTokenizer(s);
while(st.hasMoreTokens()){
res += st.nextToken().charAt(0);
}
return res.toUpperCase();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<GiangVien> a = new ArrayList<>();
sc.nextLine();
for(int i=1; i<=n; i++){
String ten = sc.nextLine();
String s = sc.nextLine();
String khoa = conv(s);
a.add(new GiangVien(i, ten, khoa));
}
int t = sc.nextInt();
sc.nextLine();
while(t-- > 0){
String s = sc.nextLine();
s = conv(s);
System.out.println("DANH SACH GIANG VIEN BO MON " + s + ":");
for(GiangVien i : a){
if(i.getKhoa().equals(s))
System.out.println(i);
}
}
}
}