-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path듣보잡.java
More file actions
45 lines (37 loc) · 1.29 KB
/
듣보잡.java
File metadata and controls
45 lines (37 loc) · 1.29 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.util.*;
import java.lang.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
Map<String, Integer> nCount = new HashMap<>();
Map<String, Integer> mCount = new HashMap<>();
for (int i = 0; i < n + m; i++) {
String input = br.readLine();
if (i < n) {
nCount.put(input, nCount.getOrDefault(input, 0) + 1);
} else {
mCount.put(input, mCount.getOrDefault(input, 0) + 1);
}
}
List<String> res = new ArrayList<>();
int cnt = 0;
for (String key : nCount.keySet()) {
if (mCount.containsKey(key)) {
cnt++;
res.add(key);
}
}
Collections.sort(res);
StringBuilder sb = new StringBuilder();
sb.append(cnt).append("\n");
for (String name : res) {
sb.append(name).append("\n");
}
System.out.println(sb);
}
}