forked from animesh0353/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
The British and American Style of Spelling
46 lines (42 loc) · 1.26 KB
/
The British and American Style of Spelling
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
42
43
44
45
46
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. */
try{
Scanner in = new Scanner(System.in);
int n = Integer.parseInt(in.nextLine());
String regex = ".*[z][e]$";
Map<String, Integer> map = new HashMap<String, Integer>();
for (int i = 0; i < n; i++)
{
String string = in.nextLine();
String[] str = string.split(" ");
for (int j = 0; j < str.length; j++) {
if(map.containsKey(str[j]))
{
int freq = map.get(str[j]);
map.put(str[j], ++freq);
}
else
map.put(str[j], 1);
}
}
int t = Integer.parseInt(in.nextLine());
for (int i = 0; i < t; i++) {
String string = in.nextLine();
int count = 0;
if(map.containsKey(string))
count = map.get(string);
char[] ch = string.toCharArray();
ch[string.length() -2] = 's';
String st1 = new String(ch);
if(map.containsKey(st1))
count += map.get(st1);
System.out.println(count);
}
}
catch(Exception e){
e.printStackTrace();
}
}
}