Advertisement
desislava_topuzakova

Untitled

Dec 9th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. package FinalExam;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.LinkedHashMap;
  5. import java.util.Map;
  6. import java.util.Scanner;
  7. import java.util.regex.Pattern;
  8.  
  9. public class Ex3 {
  10. public static void main(String[] args) {
  11. Scanner scanner = new Scanner(System.in);
  12.  
  13. String[] input = scanner.nextLine().split(Pattern.quote("|"));
  14. Map<String, ArrayList<String>> notes = new LinkedHashMap<>();
  15.  
  16. for (int i = 0; i < input.length; i++) {
  17.  
  18. String[] line = input[i].trim().split(": ");
  19. if (!notes.containsKey(line[0])) {
  20. notes.put(line[0], new ArrayList<>());
  21. notes.get(line[0]).add(line[1]);
  22. }else {
  23. notes.get(line[0]).add(line[1]);
  24. }
  25.  
  26. }
  27.  
  28. String[] words = scanner.nextLine().split(Pattern.quote(" | "));
  29.  
  30. String end = scanner.nextLine();
  31.  
  32. if (end.equals("Test")){
  33.  
  34. for (String word : words) {
  35. String clear = word.trim();
  36. if(notes.containsKey(clear)){
  37. System.out.println(clear+":");
  38. for (Map.Entry<String, ArrayList<String>> entry : notes.entrySet()){
  39. if(entry.getKey().equals(clear)){
  40. ArrayList<String> definition = entry.getValue();
  41. for (int i = 0; i < definition.size(); i++) {
  42. System.out.println(" -" +definition.get(i));
  43. }
  44. }
  45. }
  46. }
  47. }
  48.  
  49. } else if (end.equals("Hand Over")) {
  50. for (Map.Entry<String, ArrayList<String>> entry : notes.entrySet()){
  51. System.out.printf("%s ", entry.getKey());
  52. }
  53. }
  54.  
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement