-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.java
32 lines (24 loc) Β· 926 Bytes
/
Main.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
package Hash.P1764;
import java.io.*;
import java.util.*;
public class Main {
static int N, M;
static HashMap<String, Integer> map = new HashMap<>();
static List<String> list = new ArrayList<>();
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/Hash/P1764/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
for (int i = 0; i < N+M; i++) {
map.merge(br.readLine(), 1, Integer::sum);
}
map.forEach((key, value) -> {
if (value == 2) list.add(key);
});
list.sort(String::compareTo);
System.out.println(list.size());
for (String s : list) System.out.println(s);
}
}