Advertisement
MZlatev

Untitled

Dec 4th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _2._1_On_the_Way_to_Annapurna
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. Dictionary<string, List<string>> stores = new Dictionary<string, List<string>>();
  12.  
  13. while (true)
  14. {
  15. string commands = Console.ReadLine();
  16.  
  17. if (commands == "END")
  18. {
  19. break;
  20. }
  21.  
  22. string[] commandArgs = commands.Split("->");
  23. string command = commandArgs[0];
  24. string store = commandArgs[1];
  25.  
  26. if (command == "Add")
  27. {
  28. List<string> items = commandArgs[2].Split(",").ToList();
  29.  
  30. if (items.Count == 1)
  31. {
  32. if (!stores.ContainsKey(store))
  33. {
  34. stores.Add(store, new List<string>());
  35.  
  36. foreach (var item in items)
  37. {
  38. stores[store].Add(item);
  39. }
  40. }
  41.  
  42. else
  43. {
  44. foreach (var item in items)
  45. {
  46. stores[store].Add(item);
  47.  
  48. }
  49. }
  50.  
  51. }
  52.  
  53. else if (items.Count > 1)
  54. {
  55. if (!stores.ContainsKey(store))
  56. {
  57. stores.Add(store, new List<string>());
  58.  
  59. foreach (var item in items)
  60. {
  61. stores[store].Add(item);
  62. }
  63. }
  64.  
  65. else
  66. {
  67. foreach (var item in items)
  68. {
  69. stores[store].Add(item);
  70. }
  71. }
  72.  
  73. }
  74. }
  75.  
  76. else if (command == "Remove")
  77. {
  78. if (stores.ContainsKey(store))
  79. {
  80. stores.Remove(store);
  81. }
  82. }
  83. }
  84.  
  85. Console.WriteLine("Stores list:");
  86.  
  87. foreach (var store in stores
  88. .OrderByDescending(x => x.Value.Count)
  89. .ThenByDescending(x => x.Key))
  90. {
  91. Console.WriteLine($"{store.Key}");
  92.  
  93. foreach (var item in store.Value)
  94. {
  95. Console.WriteLine($"<<{item}>>");
  96. }
  97.  
  98.  
  99. }
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement