-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ede745
commit 1f7612e
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
|
||
} | ||
} |