-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSolution.java
More file actions
22 lines (20 loc) · 787 Bytes
/
Solution.java
File metadata and controls
22 lines (20 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package Practice.DataStructures.Arrays.SparseArrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Map<String, Integer> map = new HashMap<>();
int numberOfInputLines = sc.nextInt();
for (int i = 0; i < numberOfInputLines; i++) {
String currentString = sc.next();
map.put(currentString, (map.get(currentString) == null) ? 1 : map.get(currentString) + 1);
}
int numberOfQueries = sc.nextInt();
for (int i = 0; i < numberOfQueries; i++) {
String query = sc.next();
System.out.println((map.get(query) == null) ? 0 : map.get(query));
}
}
}