Advertisement
SvetlozarDragnev

Untitled

Feb 26th, 2025
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. package AssociativeArrays;
  2.  
  3. import java.util.*;
  4.  
  5. public class WordSynonyms02 {
  6.     public static void main(String[] args) {
  7.  
  8.  
  9.         Scanner scanner = new Scanner (System.in);
  10.  
  11.         int n = Integer.parseInt(scanner.nextLine());
  12.  
  13.         Map<String, String> synonymsMap = new LinkedHashMap<>();
  14.  
  15.  
  16.         for (int i = 0; i < n ; i++) {
  17.  
  18.             String word = scanner.nextLine();
  19.             String synonym = scanner.nextLine();
  20.  
  21.             if (!synonymsMap.containsKey(word)){
  22.                 synonymsMap.put(word, synonym);
  23.             }
  24.             else {
  25.                 String currentSynonym = synonymsMap.get(word);
  26.                 synonymsMap.put(word, currentSynonym + ", " + synonym);
  27.             }
  28.  
  29.         }
  30.  
  31.         for (Map.Entry<String, String> entry : synonymsMap.entrySet()){
  32.  
  33.             System.out.println(entry.getKey() + " - " + entry.getValue());
  34.         }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement