Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NoahArk {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- HashMap<String, Integer> animals = new HashMap<>();
- int n = scanner.nextInt();
- scanner.nextLine();
- StringBuilder sb = new StringBuilder();
- while (n > 0) {
- String animal = scanner.nextLine();
- int count = 1;
- if (animals.containsKey(animal)) {
- animals.get(animal);
- animals.put(animal, count + 1);
- } else {
- animals.put(animal, 1);
- }
- n--;
- }
- animals.entrySet()
- .stream()
- .sorted(Map.Entry.<String, Integer>comparingByKey())
- .forEach(a -> sb.append(a.toString().replace("=", " "))
- .append(" ")
- .append((a.getValue() % 2 == 0) ? "Yes" : "No")
- .append(System.lineSeparator()));
- System.out.println(sb.toString().trim());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment