Advertisement
Guest User

Untitled

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