Advertisement
Guest User

Untitled

a guest
Mar 7th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 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. Dictionary<string, List<string>> words = new Dictionary<string, List<string>>();
  12.  
  13. for (int i = 1; i <= 3; i++)
  14. {
  15. string command = Console.ReadLine();
  16.  
  17. if (i == 1)
  18. {
  19. string[] commandArr = command.Split(" | ");
  20.  
  21. for (int j = 0; j < commandArr.Length; j++)
  22. {
  23. string[] resultArr = commandArr[j].Split(": ");
  24.  
  25. if (!(words.ContainsKey(resultArr[0])))
  26. {
  27. words.Add(resultArr[0], new List<string>());
  28. }
  29. words[resultArr[0]].Add(resultArr[1]);
  30. }
  31. }
  32.  
  33. else if (i == 2)
  34. {
  35. string[] checkArr = command.Split(" | ");
  36. int count = 0;
  37.  
  38. foreach (var name in words.Keys.OrderBy(k => k))
  39. {
  40. string result = checkArr[count];
  41. count++;
  42. if (words.ContainsKey(result))
  43. {
  44. Console.WriteLine($"{name}");
  45. foreach (var item in words[name].OrderByDescending(x => x.Length))
  46. {
  47.  
  48. Console.WriteLine($" -{item}");
  49.  
  50. }
  51. }
  52. }
  53. }
  54.  
  55. else
  56. {
  57. if (command == "List")
  58. {
  59. foreach (var item in words.OrderBy(x => x.Key))
  60. {
  61. Console.Write(item.Key + " ");
  62. }
  63. Console.WriteLine();
  64. }
  65.  
  66. else if (command == "End")
  67. {
  68. return;
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement