Advertisement
svetlyoek

Untitled

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