Added 13 solutions

This commit is contained in:
rshaghoulian
2017-03-18 22:17:22 -05:00
parent b1992b3e60
commit 8239026cea
30 changed files with 1945 additions and 1312 deletions
@@ -10,27 +10,20 @@ public class Solution {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
scan.nextLine(); // gets rid of pesky newline
HashMap<String, Integer> map = new HashMap<>();
/* Create and fill HashMap */
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < N; i++) {
String str = scan.nextLine();
if (map.containsKey(str)) {
map.put(str, map.get(str) + 1);
} else {
map.put(str, 1);
}
map.merge(str, 1, Integer::sum);
}
/* Query HashMap */
int Q = scan.nextInt();
scan.nextLine(); // gets rid of pesky newline
for (int i = 0; i < Q; i++) {
String str = scan.nextLine();
if (map.containsKey(str)) {
System.out.println(map.get(str));
} else {
System.out.println(0);
}
System.out.println(map.getOrDefault(str, 0));
}
}
}