Advertisement
MZlatev

Untitled

Dec 4th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 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 (!stores.ContainsKey(store))
  31. {
  32. stores.Add(store, new List<string>());
  33.  
  34. foreach (var item in items)
  35. {
  36. stores[store].Add(item);
  37. }
  38. }
  39.  
  40. else
  41. {
  42. foreach (var item in items)
  43. {
  44.  
  45. stores[store].Add(item);
  46.  
  47. }
  48. }
  49. }
  50.  
  51.  
  52. else if (command == "Remove")
  53. {
  54. if (stores.ContainsKey(store))
  55. {
  56. stores.Remove(store);
  57. }
  58. }
  59. }
  60.  
  61.  
  62. Console.WriteLine("Stores list:");
  63.  
  64. foreach (var store in stores
  65. .OrderByDescending(x => x.Value.Count)
  66. .ThenByDescending(x => x.Key))
  67. {
  68. Console.WriteLine($"{store.Key}");
  69.  
  70. foreach (var item in store.Value)
  71. {
  72. Console.WriteLine($"<<{item}>>");
  73. }
  74.  
  75.  
  76. }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement