elena1234

WordSynonyms-withDictionary

Oct 25th, 2020 (edited)
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace WordSynonyms
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.             int number = int.Parse(Console.ReadLine());
  12.             var dictionary = new Dictionary<string, List<string>>();
  13.  
  14.             for (int i = 0; i <= number-1; i++)
  15.             {
  16.                 string word = Console.ReadLine().ToLower();
  17.                 string synonyms = Console.ReadLine().ToLower();
  18.  
  19.                 if (dictionary.ContainsKey(word) == false)
  20.                 {
  21.                     dictionary[word] = new List<string>();
  22.                     dictionary[word].Add(synonyms);
  23.                 }
  24.  
  25.                 else
  26.                 {
  27.                     dictionary[word].Add(synonyms);
  28.                 }
  29.             }
  30.  
  31.             foreach (var item in dictionary)
  32.             {
  33.                 Console.WriteLine($"{item.Key} - {string.Join(", ",item.Value)}");
  34.             }
  35.  
  36.         }
  37.  
  38.      }
  39.      
  40.     }
  41.  
  42.  
  43.  
Add Comment
Please, Sign In to add comment