Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Scanner;
- import java.util.function.BiConsumer;
- public class BloodyTypes {
- static String group(String a) {
- return "" + a.charAt(0) + a.charAt(a.length() - 1);
- // "" + ^^^^^ this is a character
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int N = Integer.parseInt(scanner.nextLine());
- HashMap<String, Integer> mp = new HashMap<String, Integer>();
- // Blood Type => # of people
- for (int i = 0; i < N; i++) {
- String line = scanner.nextLine();
- String[] s = line.split(" ");
- int many = mp.getOrDefault(group(s[2]), 0);
- mp.put(group(s[2]), many + 1);
- }
- BiConsumer<String, Integer> print = (String key, Integer value) -> {
- System.out.println(key + ": " + value);
- };
- mp.forEach(print);
- String query = scanner.nextLine();
- int result = mp.getOrDefault(group(query), 0);
- System.out.println("My beautiful result: " + result);
- // for (String key: mp.keySet()) {
- // Integer value = mp.get(key);
- // System.out.println(key + ": " + value);
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment