borovaneca

Dictiionary

Apr 3rd, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package Hogwarts;
  2.  
  3. import java.util.*;
  4.  
  5. public class Dictionary {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.  
  10.         Map<String, List<String>> notebook = new LinkedHashMap<>();
  11.         for (String word : scanner.nextLine().split("\\s+\\|\\s+")) {
  12.             String[] wordAndDefinition = word.split(": ");
  13.             notebook.putIfAbsent(wordAndDefinition[0], new ArrayList<>());
  14.             notebook.get(wordAndDefinition[0]).add(wordAndDefinition[1]);
  15.         }
  16.         List<String> teacherWords = new ArrayList<>(Arrays.asList(scanner.nextLine().split("\\s+\\|\\s+")));
  17.         String command = scanner.nextLine();
  18.         if ("Test".equals(command)) {
  19.             teacherWords.forEach(item -> {
  20.                 if (notebook.containsKey(item)) {
  21.                     System.out.printf("%s:\n", item);
  22.                     notebook.get(item).forEach(definition -> System.out.printf(" -%s\n", definition));
  23.                 }
  24.             });
  25.         } else if ("Hand Over".equals(command)) {
  26.             System.out.println(String.join(" ", notebook.keySet()));
  27.  
  28.         }
  29.  
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment