Advertisement
mastersan12

Dictionary

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