- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogrammers92334.java
More file actions
Latest commit
79 lines (72 loc) · 2.75 KB
/
Copy pathprogrammers92334.java
File metadata and controls
79 lines (72 loc) · 2.75 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
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
packageProgrammers;
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.util.*;
publicclassprogrammers92334 {
publicstaticvoidmain(String[] args) throwsIOException {
Solution92334sc = newSolution92334();
BufferedReaderin = newBufferedReader(newInputStreamReader(System.in));
intk = 0;
/*
input case1
"muzi", "frodo", "apeach", "neo"
"muzi frodo","apeach frodo","frodo neo","muzi neo","apeach muzi"
2
input case2
"con", "ryan"
"ryan con", "ryan con", "ryan con", "ryan con"
3
*/
StringTokenizerstringTokenizer = newStringTokenizer(in.readLine(), ", ");
inti = 0;
String[] id_list = newString[stringTokenizer.countTokens()];
while (stringTokenizer.hasMoreTokens()) {
id_list[i] = stringTokenizer.nextToken();
id_list[i] = id_list[i].substring(1, id_list[i].length() - 1);
i++;
}
stringTokenizer = newStringTokenizer(in.readLine(), ",");
i = 0;
String[] report = newString[stringTokenizer.countTokens()];
while (stringTokenizer.hasMoreTokens()) {
report[i] = stringTokenizer.nextToken();
report[i] = report[i].substring(1, report[i].length() - 1);
i++;
}
k = Integer.parseInt(in.readLine());
for (intj = 0; j < id_list.length; j++)
System.out.println(Arrays.stream(sc.solution(id_list, report, k)).toArray()[j]);
}
}
classSolution92334 {
publicint[] solution(String[] id_list, String[] report, intk) {
int[] answer = newint[id_list.length];
HashMap<String, Set<String>> reporterArr = newHashMap<>();
HashMap<String, Integer> singoArr = newHashMap<>();
for (Stringid : id_list) {
singoArr.put(id, 0);
reporterArr.put(id, newHashSet<String>());
}
for (Stringcur : report) {
StringTokenizerstr = newStringTokenizer(cur, " ");
Stringreporter = str.nextToken();
Stringsingo = str.nextToken();
if (reporterArr.get(reporter).add(singo)) {
singoArr.put(singo, singoArr.get(singo).intValue() + 1);
}
}
for (Stringcur : report) {
StringTokenizerstr = newStringTokenizer(cur, " ");
Stringreporter = str.nextToken();
Stringsingo = str.nextToken();
if (singoArr.get(singo).intValue() < k) {
reporterArr.get(reporter).remove(singo);
}
}
for (inti = 0; i < id_list.length; i++) {
answer[i] = reporterArr.get(id_list[i]).size();
}
returnanswer;
}
}