Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class dictionary {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- Map<String, ArrayList<String>> dict = new TreeMap<>();
- String[] line1 = scan.nextLine().split("\\s+\\|\\s+");
- for (String s : line1) {
- String[] data = s.split(":\\s+");
- dict.putIfAbsent(data[0], new ArrayList<>());
- dict.get(data[0]).add(data[1]);
- }
- String[] line2 = scan.nextLine().split("\\s+\\|\\s+");
- String command = scan.nextLine();
- if (command.equals("End")) {
- dict.forEach((key, value) -> {
- System.out.printf("%s%n", key);
- value.stream().sorted((m1, m2) -> Integer.compare(m2.length(), m1.length()))
- .forEach(f -> System.out.println(String.format("-%s", f)));
- });
- } else if (command.equals("List")) {
- dict.forEach((key, value) -> System.out.printf("%s ", key));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment