Advertisement
deyanmalinov

02. Word Synonyms

Mar 15th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. package DPM;
  2. import java.text.DecimalFormat;
  3. import java.util.*;
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         int num = Integer.parseInt(scan.nextLine());
  8.         Map <String, List<String>> newMap = new LinkedHashMap<>();
  9.         for (int i = 0; i < num; i++) {
  10.             String str1 = scan.nextLine();
  11.             String str2 = scan.nextLine();
  12.             newMap.putIfAbsent(str1, new ArrayList<>());
  13.             newMap.get(str1).add(str2);
  14.         }
  15.         for (Map.Entry<String, List<String>> entry : newMap.entrySet()) {
  16.             String value1 = String.join(", ", entry.getValue());
  17.             System.out.printf("%s - %s\n", entry.getKey(), value1);
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement