Advertisement
Guest User

Untitled

a guest
Mar 21st, 2020
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _1._Santa_s_Present_Factory
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11.  
  12. Stack<int> myStackMaterials = new Stack<int>(Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList());
  13. Queue<int> myQueueMagicLevel = new Queue<int>(Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList());
  14.  
  15. Dictionary<string, int> myDictionary = new Dictionary<string, int>();
  16.  
  17. while (myStackMaterials.Count > 0 && myQueueMagicLevel.Count > 0)
  18. {
  19. if (myStackMaterials.Peek() == 0 || myQueueMagicLevel.Peek() == 0)
  20. {
  21. if (myStackMaterials.Peek() == 0)
  22. {
  23. myStackMaterials.Pop();
  24. }
  25. if (myQueueMagicLevel.Peek() == 0)
  26. {
  27. myQueueMagicLevel.Dequeue();
  28. }
  29. continue;
  30. }
  31.  
  32. int result = myStackMaterials.Peek() * myQueueMagicLevel.Peek();
  33.  
  34. if (result > 0)
  35. {
  36. switch (result)
  37. {
  38. case 150:
  39. if (myDictionary.ContainsKey("Doll"))
  40. {
  41. myDictionary["Doll"] += 1;
  42. }
  43. else
  44. {
  45. myDictionary.Add("Doll", 1);
  46. }
  47. myStackMaterials.Pop();
  48. myQueueMagicLevel.Dequeue();
  49. break;
  50. case 250:
  51. if (myDictionary.ContainsKey("Wooden train"))
  52. {
  53. myDictionary["Wooden train"] += 1;
  54. }
  55. else
  56. {
  57. myDictionary.Add("Wooden train", 1);
  58. }
  59. myStackMaterials.Pop();
  60. myQueueMagicLevel.Dequeue();
  61. break;
  62. case 300:
  63. if (myDictionary.ContainsKey("Teddy bear"))
  64. {
  65. myDictionary["Teddy bear"] += 1;
  66. }
  67. else
  68. {
  69. myDictionary.Add("Teddy bear", 1);
  70. }
  71. myStackMaterials.Pop();
  72. myQueueMagicLevel.Dequeue();
  73. break;
  74. case 400:
  75. if (myDictionary.ContainsKey("Bicycle"))
  76. {
  77. myDictionary["Bicycle"] += 1;
  78. }
  79. else
  80. {
  81. myDictionary.Add("Bicycle", 1);
  82. }
  83. myStackMaterials.Pop();
  84. myQueueMagicLevel.Dequeue();
  85. break;
  86. default:
  87. int tempMaterialValue = myStackMaterials.Pop() + 15;
  88. myStackMaterials.Push(tempMaterialValue);
  89.  
  90. myQueueMagicLevel.Dequeue();
  91. break;
  92. }
  93. }
  94. else if (result < 0)
  95. {
  96. int sum = myStackMaterials.Pop() + myQueueMagicLevel.Dequeue();
  97. myStackMaterials.Push(sum);
  98. }
  99. }
  100.  
  101. if ((myDictionary.ContainsKey("Doll") && myDictionary.ContainsKey("Wooden train")) || (myDictionary.ContainsKey("Teddy bear") && myDictionary.ContainsKey("Bicycle")))
  102. {
  103. Console.WriteLine($"The presents are crafted! Merry Christmas!");
  104. }
  105. else
  106. {
  107. Console.WriteLine("No presents this Christmas!");
  108. }
  109.  
  110. if (myStackMaterials.Count > 0)
  111. {
  112. Console.WriteLine("Materials left: " + string.Join(", ", myStackMaterials).ToString());
  113. }
  114. if (myQueueMagicLevel.Count > 0)
  115. {
  116. Console.WriteLine("Magic left: " + string.Join(", ", myQueueMagicLevel).ToString());
  117. }
  118.  
  119. myDictionary = myDictionary.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
  120.  
  121. foreach (var item in myDictionary)
  122. {
  123. Console.WriteLine($"{item.Key}: {item.Value}".ToString());
  124. }
  125. }
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement