-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsparse array
More file actions
41 lines (34 loc) · 1.2 KB
/
sparse array
File metadata and controls
41 lines (34 loc) · 1.2 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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan = new Scanner(System.in);
int noOfStrings = scan.nextInt();
//scan.nextLine();
Map<String, Integer> hashMap = new HashMap<>();
for(int i = 0; i < noOfStrings; i++){
String s = scan.next();
if(hashMap.containsKey(s))
hashMap.put(s, hashMap.get(s) + 1);
else
hashMap.put(s, 1);
scan.nextLine();
}
int noOfQueries = scan.nextInt();
scan.nextLine();
//System.out.print(noOfQueries);
// for(int i = 0; i < noOfQueries; i++){
// String s= scan.nextLine();
// System.out.println(s);
//}
for(int i = 0; i < noOfQueries; i++){
String s = scan.nextLine();
if(hashMap.containsKey(s)){
System.out.println(hashMap.get(s));
}
else
System.out.println(0);
}
}
}