nassss

Untitled

Mar 26th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Santa_sHelper
  6. {
  7. class Program
  8. {
  9. static Queue<string> comandResult = new Queue<string>();
  10. static Dictionary<string, List<Tuple<string, double>>> santaList = new Dictionary<string, List<Tuple<string, double>>>();
  11. static void Main(string[] args)
  12. {
  13. int commandNumber = int.Parse(Console.ReadLine());
  14. string input;
  15. for (int i = 0; i < commandNumber; i++)
  16. {
  17. input = Console.ReadLine();
  18. switch (input.Split()[0])
  19. {
  20. case "AddWish":
  21. AddWish(input.Substring(8));
  22. break;
  23. case "DeleteWishes":
  24. DeleteWishes(input.Substring(13));
  25. break;
  26. case "FindWishesByPriceRange":
  27. WishesInPriceRange(input.Substring(23));
  28. break;
  29. case "FindWishesByChild":
  30. WishesByChildren(input.Substring(18));
  31. break;
  32. default:
  33. break;
  34. }
  35. }
  36. Console.WriteLine(string.Join(Environment.NewLine, comandResult));
  37. }
  38.  
  39. private static void AddWish(string wish)
  40. {
  41. string item = wish.Split(';')[0];
  42. double price = double.Parse(wish.Split(';')[1]);
  43. string child = wish.Split(';')[2];
  44. Tuple<string, double> itemInfo = new Tuple<string, double>(item, price);
  45. if (santaList.ContainsKey(child))
  46. {
  47. santaList[child].Add(itemInfo);
  48. }
  49. else
  50. {
  51. santaList.Add(child, new List<Tuple<string, double>>());
  52. santaList[child].Add(itemInfo);
  53. }
  54. comandResult.Enqueue("Wish added");
  55. }
  56.  
  57. private static void DeleteWishes(string child)
  58. {
  59. int wishes;
  60. if (santaList.ContainsKey(child))
  61. {
  62. wishes = santaList[child].Count;
  63. santaList.Remove(child);
  64. comandResult.Enqueue($"{wishes} Wishes deleted");
  65. }
  66. else
  67. {
  68. comandResult.Enqueue("No Wishes found");
  69. }
  70. }
  71.  
  72. private static void WishesInPriceRange(string prices)
  73. {
  74. List<string> items = new List<string>();
  75. double min = double.Parse(prices.Split(';')[0]);
  76. double max = double.Parse(prices.Split(';')[1]);
  77. foreach (var child in santaList)
  78. {
  79. foreach (var wish in child.Value)
  80. {
  81. if (wish.Item2 >= min && wish.Item2 <= max)
  82. {
  83. items.Add("{" + $"{wish.Item1};{child.Key};{wish.Item2:0.00}" + "}");
  84. }
  85. }
  86. }
  87. if (items.Count > 0)
  88. {
  89. items.Sort();
  90. comandResult.Enqueue(string.Join(Environment.NewLine, items));
  91. }
  92. else
  93. {
  94. comandResult.Enqueue("No Wishes found");
  95. }
  96. }
  97.  
  98. private static void WishesByChildren(string child)
  99. {
  100. List<string> items = new List<string>();
  101. if (santaList.ContainsKey(child))
  102. {
  103. foreach (var wish in santaList[child])
  104. {
  105. items.Add("{" + $"{wish.Item1};{child};{wish.Item2:0.00}" + "}");
  106. }
  107. items.Sort();
  108. comandResult.Enqueue(string.Join(Environment.NewLine, items));
  109. }
  110. else
  111. {
  112. comandResult.Enqueue("No Wishes found");
  113. }
  114. }
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment