iLLcheff

Noah's Ark

Jan 18th, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. public class NoahArk {
  2.     public static void main(String[] args) {
  3.         Scanner scanner = new Scanner(System.in);
  4.         HashMap<String, Integer> animals = new HashMap<>();
  5.         int n = scanner.nextInt();
  6.         scanner.nextLine();
  7.         StringBuilder sb = new StringBuilder();
  8.         while (n > 0) {
  9.             String animal = scanner.nextLine();
  10.             int count = 1;
  11.             if (animals.containsKey(animal)) {
  12.                 animals.get(animal);
  13.                 animals.put(animal, count + 1);
  14.             } else {
  15.                 animals.put(animal, 1);
  16.             }
  17.             n--;
  18.         }
  19.         animals.entrySet()
  20.                 .stream()
  21.                 .sorted(Map.Entry.<String, Integer>comparingByKey())
  22.                 .forEach(a -> sb.append(a.toString().replace("=", " "))
  23.                         .append(" ")
  24.                         .append((a.getValue() % 2 == 0) ? "Yes" : "No")
  25.                         .append(System.lineSeparator()));
  26.         System.out.println(sb.toString().trim());
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment