la-ma-rin

dictionary

Apr 6th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class dictionary {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         Map<String, ArrayList<String>> dict = new TreeMap<>();
  8.  
  9.         String[] line1 = scan.nextLine().split("\\s+\\|\\s+");
  10.  
  11.         for (String s : line1) {
  12.             String[] data = s.split(":\\s+");
  13.  
  14.             dict.putIfAbsent(data[0], new ArrayList<>());
  15.             dict.get(data[0]).add(data[1]);
  16.         }
  17.  
  18.         String[] line2 = scan.nextLine().split("\\s+\\|\\s+");
  19.  
  20.         String command = scan.nextLine();
  21.  
  22.         if (command.equals("End")) {
  23.  
  24.             dict.forEach((key, value) -> {
  25.                 System.out.printf("%s%n", key);
  26.                 value.stream().sorted((m1, m2) -> Integer.compare(m2.length(), m1.length()))
  27.                         .forEach(f -> System.out.println(String.format("-%s", f)));
  28.             });
  29.  
  30.         } else if (command.equals("List")) {
  31.  
  32.             dict.forEach((key, value) -> System.out.printf("%s ", key));
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment