Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ArrivingInKathmandu
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var storesAndItems = new Dictionary<string, List<string>>();
  12.  
  13. string commands;
  14.  
  15. while ((commands = Console.ReadLine()) != "END")
  16. {
  17. List<string> splitedCommand = commands.Split("->").ToList();
  18. string toDo = splitedCommand[0];
  19.  
  20. if (toDo == "Add")
  21. {
  22. string store = splitedCommand[1];
  23. List<string> items = splitedCommand[2].Split(",").ToList();
  24. if (!storesAndItems.ContainsKey(store))
  25. {
  26. storesAndItems[store] = new List<string>();
  27. }
  28. foreach (var item in items)
  29. {
  30. storesAndItems[store].Add(item);
  31. }
  32. }
  33. else if (toDo == "Remove")
  34. {
  35. string storeToRemove = splitedCommand[1];
  36. if (storesAndItems.ContainsKey(storeToRemove))
  37. {
  38. storesAndItems.Remove(storeToRemove);
  39.  
  40. }
  41. }
  42. }
  43. Console.WriteLine("Stores list: ");
  44. foreach (var store in storesAndItems.OrderByDescending(x => x.Value.Count).ThenByDescending(x => x.Key))
  45. {
  46. Console.WriteLine($"{store.Key}");
  47. foreach (var item in store.Value)
  48. {
  49. Console.WriteLine($"<<{item}>>");
  50.  
  51. }
  52. }
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement