Advertisement
Spocoman

03. Word Synonyms

Apr 8th, 2023 (edited)
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace WordSynonyms
  6. {
  7.     class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             Dictionary<string, List<string>> words = new Dictionary<string, List<string>>();
  12.  
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 string word = Console.ReadLine();
  18.                 string synonym = Console.ReadLine();
  19.  
  20.                 if (!words.ContainsKey(word))
  21.                 {
  22.                     words.Add(word, new List<string>());
  23.                 }
  24.                
  25.                 words[word].Add(synonym);
  26.             }
  27.          
  28.             foreach (var word in words)
  29.             {
  30.                 Console.Write($"{word.Key} - {string.Join(", ", word.Value)}\n");
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement