TheBulgarianWolf

Word Synonyms

Feb 20th, 2021
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace WordSynonyms
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Enter the number of pairs you want to enter: ");
  11.             int times = int.Parse(Console.ReadLine());
  12.             var words = new Dictionary<string, List<string>>();
  13.             for(int i = 0; i < times; i++)
  14.             {
  15.                 string word = Console.ReadLine();
  16.                 string synonym = Console.ReadLine();
  17.                 if (words.ContainsKey(word) == false)
  18.                 {
  19.                     words.Add(word, new List<string>());
  20.                 }
  21.                 words[word].Add(synonym);
  22.                
  23.  
  24.             }
  25.  
  26.             foreach(var word in words)
  27.             {
  28.                 Console.Write(word.Key + " -> ");
  29.                 int counts = 0;
  30.                 foreach(string synonym in word.Value)
  31.                 {
  32.                    
  33.                     if(counts == word.Value.Count-1)
  34.                     {
  35.                         Console.Write(synonym);
  36.                     }
  37.                     else
  38.                     {
  39.                         Console.Write(synonym + ",");
  40.                         counts++;
  41.                     }
  42.                 }
  43.                 Console.WriteLine();
  44.             }
  45.         }
  46.     }
  47. }
  48.  
Add Comment
Please, Sign In to add comment