Advertisement
dMundov

01._Dictionary

Apr 6th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01._Dictionary
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] inputData = Console.ReadLine().Split(" | ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  12.             Dictionary<string, List<string>> wordDefinitions = new Dictionary<string, List<string>>();
  13.          
  14.  
  15.             for (int i = 0; i < inputData.Length; i++)
  16.             {
  17.                 string[] currentWordDef = inputData[i].Split(": ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  18.                 string word = currentWordDef[0];
  19.                 string definition = currentWordDef[1];
  20.  
  21.                 if (!wordDefinitions.ContainsKey(word))
  22.                 {
  23.                     List<string> currDef = new List<string>();
  24.                     currDef.Add(definition);
  25.                     wordDefinitions.Add(word, currDef);
  26.                 }
  27.                 else
  28.                 {
  29.                     wordDefinitions[word].Add(definition);
  30.                 }
  31.             }
  32.  
  33.             string[] wordsToPrint = Console.ReadLine().Split(" | ").ToArray();
  34.             for (int i = 0; i < wordsToPrint.Length; i++)
  35.             {
  36.                 string word = wordsToPrint[i];
  37.                 if (wordDefinitions.ContainsKey(word))
  38.                 {
  39.                     Console.WriteLine(word);
  40.                     foreach (var definition in wordDefinitions[word].OrderByDescending(x => x.Length))
  41.                     {
  42.                         Console.WriteLine($" -{definition}");
  43.                     }
  44.                 }
  45.             }
  46.             string command = Console.ReadLine();
  47.             if (command == "List")
  48.             {
  49.                 foreach (var word in wordDefinitions.Keys.OrderBy(x => x))
  50.                 {
  51.                     Console.Write(word + " ");
  52.                 }
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement