Files

30 lines
886 B
Java
Raw Permalink Normal View History

2017-02-18 23:43:07 -06:00
// Author: Rodney Shaghoulian
2018-07-27 16:45:56 -07:00
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
2017-02-18 23:43:07 -06:00
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
2017-03-18 22:17:22 -05:00
/* Create and fill HashMap */
HashMap<String, Integer> map = new HashMap<>();
2017-02-18 23:43:07 -06:00
for (int i = 0; i < N; i++) {
String str = scan.nextLine();
2017-03-18 22:17:22 -05:00
map.merge(str, 1, Integer::sum);
2017-02-18 23:43:07 -06:00
}
2017-03-18 22:17:22 -05:00
/* Query HashMap */
2017-02-18 23:43:07 -06:00
int Q = scan.nextInt();
scan.nextLine(); // gets rid of pesky newline
for (int i = 0; i < Q; i++) {
String str = scan.nextLine();
2017-03-18 22:17:22 -05:00
System.out.println(map.getOrDefault(str, 0));
2017-02-18 23:43:07 -06:00
}
}
}