Again_89

1ва задача

Apr 6th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 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()
  10. {
  11. var words = new Dictionary<string, List<string>>();
  12.  
  13. var firstLine = Console.ReadLine().Split(" | ");
  14.  
  15. for (int i = 0; i < firstLine.Length; i++)
  16. {
  17. var wordsWithDefinitions = firstLine[i].Split(": ");
  18. var word = wordsWithDefinitions[0];
  19. var definition = wordsWithDefinitions[1];
  20. if (!words.ContainsKey(word))
  21. {
  22. words[word] = new List<string>();
  23. words[word].Add(definition);
  24. }
  25. else if (words.ContainsKey(word) && !words[word].Contains(definition))
  26. {
  27. words[word].Add(definition);
  28. }
  29. }
  30.  
  31. var secondLine = Console.ReadLine().Split(" | ");
  32.  
  33. for (int i = 0; i < secondLine.Length; i++)
  34. {
  35. if (words.ContainsKey(secondLine[i]))
  36. {
  37. Console.WriteLine($"{secondLine[i]}");
  38. foreach (var definition in words[secondLine[i]].OrderByDescending(x => x.Length))
  39. {
  40. Console.WriteLine($" -{definition}");
  41. }
  42. }
  43. }
  44.  
  45. var thirdLine = Console.ReadLine();
  46.  
  47. if (thirdLine == "End")
  48. {
  49. return;
  50. }
  51. else if (thirdLine == "List")
  52. {
  53. foreach (var word in words.OrderBy(x => x.Key))
  54. {
  55. Console.Write($"{word.Key}" + " ");
  56. }
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment