-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathSolution.java
More file actions
27 lines (23 loc) · 797 Bytes
/
Solution.java
File metadata and controls
27 lines (23 loc) · 797 Bytes
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
// github.com/RodneyShag
import java.util.Scanner;
import java.util.HashMap;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
scan.nextLine(); // gets rid of pesky newline
/* Create and fill HashMap */
HashMap<String, Integer> map = new HashMap();
for (int i = 0; i < N; i++) {
String str = scan.nextLine();
map.merge(str, 1, Integer::sum);
}
/* Query HashMap */
int Q = scan.nextInt();
scan.nextLine(); // gets rid of pesky newline
for (int i = 0; i < Q; i++) {
String str = scan.nextLine();
System.out.println(map.getOrDefault(str, 0));
}
}
}