-
Notifications
You must be signed in to change notification settings - Fork 0
/
JudgingTroubles.java
40 lines (31 loc) · 1.01 KB
/
JudgingTroubles.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
import java.util.*;
class JudgingTroubles {
public static void main(String[] args) {
intersection();
}
public static void intersection() {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
HashMap<String, Integer> map = new HashMap<>();
int numSubmissions = in.nextInt();
String result;
//number of intersections
int numInter = 0;
for (int i = 0; i < numSubmissions; i++) {
result = in.next();
map.put(result, map.getOrDefault(result, 0) + 1);
}
HashMap<String, Integer> map2 = new HashMap<>();
for (int i = 0; i < numSubmissions; i++) {
result = in.next();
map2.put(result, map2.getOrDefault(result, 0) + 1);
}
for(String key : map.keySet()) {
if (map2.containsKey(key)) {
numInter += Math.min(map.get(key), map2.get(key));
}
}
System.out.println(numInter);
}
}
}