neZnam121

Untitled

Dec 5th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Dictionary
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var firstString = Console.ReadLine().Split(" | ");
  11.             var listDictionary = new SortedDictionary<string, List<string>>();
  12.             foreach (var item in firstString)
  13.             {
  14.                 var wordDefinition = item.Split(": ");
  15.                 if (!listDictionary.ContainsKey(wordDefinition[0]))
  16.                 {
  17.                     listDictionary.Add(wordDefinition[0], new List<string>() { $" -{wordDefinition[1]}" });
  18.                 }
  19.                 else
  20.                 {
  21.                     listDictionary[wordDefinition[0]].Add($" -{wordDefinition[1]}");
  22.                 }
  23.             }
  24.             var secondCheckWordString = Console.ReadLine().Split(" | ");
  25.             foreach (var word in secondCheckWordString)
  26.             {
  27.                 if (listDictionary.ContainsKey(word))
  28.                 {
  29.                     foreach (var item in listDictionary.Where(x => x.Key == word))
  30.                     {
  31.                         Console.WriteLine($"{ item.Key}:");
  32.                         Console.WriteLine(string.Join("\n", item.Value.OrderByDescending(x => x.Length)));
  33.                     }
  34.                 }
  35.             }
  36.             var thirdString = Console.ReadLine();
  37.             if (thirdString == "Hand Over")
  38.             {
  39.                 Console.WriteLine(string.Join(" ", listDictionary.Select(x => x.Key)));
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment