Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package a3_Demo_FinalExem_6Apr2019;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class P1_Dictionary {
- public static void main(String[] args) {
- @SuppressWarnings("resource")
- Scanner sc = new Scanner(System.in);
- String[] input = sc.nextLine().split("\\s+\\|\\s+");
- Map<String, List<String>> words = new TreeMap<>();
- for (int i = 0; i < input.length; i++) {
- String[] tokens = input[i].split(":\\s+");
- String word = tokens[0];
- String def = tokens[1];
- if (!words.containsKey(word)) {
- words.put(word, new ArrayList<>());
- words.get(word).add(def);
- } else {
- words.get(word).add(def);
- }
- }
- String[] wordsInDic = sc.nextLine().split("\\s+\\|\\s+");
- String option = sc.nextLine();
- switch (option) {
- case "End":
- for (int i = 0; i < wordsInDic.length; i++) {
- if (words.containsKey(wordsInDic[i])) {
- System.out.println(wordsInDic[i]);
- words.get(wordsInDic[i]).stream().sorted((d1, d2) -> {
- int sort = Integer.compare(d2.length(), d1.length());
- return sort;
- }).forEach(e -> System.out.println(String.format(" -%s", e.toString().replaceAll("\\[|\\]", ""))));
- }
- }
- break;
- case "List":
- List<String> keys = new ArrayList<>();
- words.keySet().stream().forEach(e -> keys.add(e));
- System.out.println(keys.toString().replaceAll("\\[|\\]|,", ""));
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement