mastersan12

Dictionary 2

Apr 13th, 2019
72
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. using System.Numerics;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8.  
  9. namespace solutions
  10. {
  11.     class Program
  12.     {
  13.         public static void Main()
  14.         {
  15.             var input = Console.ReadLine().Split(" | ");
  16.             var someWords = Console.ReadLine().Split(" | ");
  17.             var line = Console.ReadLine();
  18.  
  19.             var result = new SortedDictionary<string, List<string>>();
  20.  
  21.             foreach (var item in input)
  22.             {
  23.                 var wordAndDefinition = item.Split(": ");
  24.                 var word = wordAndDefinition[0];
  25.                 var definition = wordAndDefinition[1];
  26.  
  27.                 if (!result.ContainsKey(word))
  28.                 {
  29.                     result.Add(word, new List<string>());
  30.                     result[word].Add(definition);
  31.                 }
  32.                 else
  33.                 {
  34.                     if (!result[word].Contains(definition))
  35.                     {
  36.                         result[word].Add(definition);
  37.                     }
  38.                 }
  39.             }
  40.  
  41.             foreach (var word in someWords)
  42.             {
  43.                 if (result.ContainsKey(word))
  44.                 {
  45.                     Console.WriteLine($"{word}");
  46.  
  47.                     foreach (var value in result[word].OrderByDescending(v => v.Count().ToString()))
  48.                     {
  49.                         Console.WriteLine($" -{value}");
  50.                     }
  51.                 }
  52.             }
  53.  
  54.             switch (line)
  55.             {
  56.                 case "End": return;
  57.                 case "List":
  58.                     foreach (var item in result)
  59.                     {
  60.                         Console.Write($"{item.Key} ");
  61.                     }
  62.                     Console.WriteLine();
  63.                     break;
  64.             }
  65.         }
  66.     }
  67. }
Add Comment
Please, Sign In to add comment