mitkonikov

Bloody Types

Jan 29th, 2023
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Scanner;
  3. import java.util.function.BiConsumer;
  4.  
  5. public class BloodyTypes {
  6.     static String group(String a) {
  7.         return "" + a.charAt(0) + a.charAt(a.length() - 1);
  8.         //     "" +   ^^^^^ this is a character
  9.     }
  10.     public static void main(String[] args) {
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         int N = Integer.parseInt(scanner.nextLine());
  14.         HashMap<String, Integer> mp = new HashMap<String, Integer>();
  15.         // Blood Type => # of people
  16.         for (int i = 0; i < N; i++) {
  17.             String line = scanner.nextLine();
  18.             String[] s = line.split(" ");
  19.             int many = mp.getOrDefault(group(s[2]), 0);
  20.             mp.put(group(s[2]), many + 1);
  21.         }
  22.        
  23.         BiConsumer<String, Integer> print = (String key, Integer value) -> {
  24.             System.out.println(key + ": " + value);
  25.         };
  26.         mp.forEach(print);
  27.  
  28.         String query = scanner.nextLine();
  29.         int result = mp.getOrDefault(group(query), 0);
  30.         System.out.println("My beautiful result: " + result);
  31.  
  32.         // for (String key: mp.keySet()) {
  33.         //     Integer value = mp.get(key);
  34.         //     System.out.println(key + ": " + value);
  35.         // }
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment