Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Dictionary
  6. {
  7. class Program
  8. {
  9. public static void Main()
  10. {
  11. var dictionary = new Dictionary<string, List<string>>();
  12. var counter = 0;
  13.  
  14. while (true)
  15. {
  16. var input = Console.ReadLine()
  17. .Split(" | ")
  18. .ToList();
  19.  
  20. counter++;
  21.  
  22. if (input[0] == "End")
  23. {
  24. break;
  25. }
  26.  
  27. if (input[0] == "List")
  28. {
  29. foreach (var word in dictionary.OrderBy(w=>w.Key))
  30. {
  31. Console.Write(word.Key + " ");
  32. }
  33. Console.WriteLine();
  34. break;
  35. }
  36.  
  37. if (counter == 1)
  38. {
  39. for (int i = 0; i < input.Count; i++)
  40. {
  41. var splittedInput = input[i].Split(": ");
  42. var word = splittedInput[0];
  43. var meaning = splittedInput[1];
  44.  
  45. if (!dictionary.ContainsKey(word))
  46. {
  47. dictionary[word] = new List<string> { meaning };
  48. }
  49. else
  50. {
  51. dictionary[word].Add(meaning);
  52. }
  53. }
  54. }
  55.  
  56. if (counter == 2)
  57. {
  58. for (int i = 0; i < input.Count; i++)
  59. {
  60. var word = input[i];
  61.  
  62. if (dictionary.ContainsKey(word))
  63. {
  64. Console.WriteLine(word);
  65. foreach (var meaning in dictionary[word].OrderByDescending(m=>m.Length))
  66. {
  67. Console.WriteLine($" -{meaning}");
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement