svetlyoek

02. Final

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