Advertisement
SensaBG

exam

Dec 1st, 2024 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4.  
  5. public class newNEwNew {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         Map<String, StringBuilder> book = new HashMap<>();
  10.         String[] notes = scanner.nextLine().split(" \\| ");
  11.  
  12.         for (String note : notes) {
  13.             String[] data = note.split(": ");
  14.             String word = data[0];
  15.             String def = data[1];
  16.            
  17.             book.putIfAbsent(word, new StringBuilder());
  18.             book.get(word).append(" -").append(def).append(System.lineSeparator());
  19.         }
  20.  
  21.         notes = scanner.nextLine().split(" \\| ");
  22.         String command = scanner.nextLine();
  23.  
  24.         boolean isExamTime = "Test".equals(command);
  25.  
  26.         for (String currentTopic : notes) {
  27.             if (book.containsKey(currentTopic)) {
  28.                 String topicFromNotes = System.lineSeparator() + book.get(currentTopic);
  29.                 System.out.print(isExamTime ? currentTopic + ":" + topicFromNotes : currentTopic + " ");
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement