Advertisement
astanchev

SpaceshipCrafting

Jun 26th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01._Spaceship_Crafting
  6. {
  7. class SpaceshipCrafting
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, int> materialQuantity = new Dictionary<string, int>();
  12. if (!materialQuantity.ContainsKey("Carbon fiber"))
  13. {
  14. materialQuantity["Carbon fiber"] = 0;
  15. }
  16. if (!materialQuantity.ContainsKey("Lithium"))
  17. {
  18. materialQuantity["Lithium"] = 0;
  19. }
  20. if (!materialQuantity.ContainsKey("Aluminium"))
  21. {
  22. materialQuantity["Aluminium"] = 0;
  23. }
  24. if (!materialQuantity.ContainsKey("Glass"))
  25. {
  26. materialQuantity["Glass"] = 0;
  27. }
  28.  
  29. int[] inputLiquids = Console.ReadLine()
  30. .Split()
  31. .Select(int.Parse)
  32. .ToArray();
  33. Queue<int> liquids = new Queue<int>(inputLiquids);
  34.  
  35. int[] inputItems = Console.ReadLine()
  36. .Split()
  37. .Select(int.Parse)
  38. .ToArray();
  39. Stack<int> items = new Stack<int>(inputItems);
  40.  
  41. while (items.Count > 0 && liquids.Count > 0)
  42. {
  43. int currentLiquid = liquids.Dequeue();
  44. int currentItem = items.Pop();
  45.  
  46. int currentMaterialValue = currentLiquid + currentItem;
  47.  
  48. if (currentMaterialValue == 100)
  49. {
  50. materialQuantity["Carbon fiber"]++;
  51. }
  52. else if (currentMaterialValue == 75)
  53. {
  54. materialQuantity["Lithium"]++;
  55. }
  56. else if (currentMaterialValue == 50)
  57. {
  58. materialQuantity["Aluminium"]++;
  59. }
  60. else if (currentMaterialValue == 25)
  61. {
  62. materialQuantity["Glass"]++;
  63. }
  64. else
  65. {
  66. currentItem += 3;
  67. items.Push(currentItem);
  68. }
  69. }
  70.  
  71. if (materialQuantity["Carbon fiber"] > 0
  72. && materialQuantity["Lithium"] > 0
  73. && materialQuantity["Aluminium"] > 0
  74. && materialQuantity["Glass"] > 0)
  75. {
  76. Console.WriteLine("Wohoo! You succeeded in building the spaceship!");
  77. }
  78. else
  79. {
  80. Console.WriteLine("Ugh, what a pity! You didn't have enough materials to build the spaceship.");
  81. }
  82.  
  83. if (liquids.Count > 0)
  84. {
  85. Console.WriteLine($"Liquids left: {string.Join(", ", liquids)}");
  86. }
  87. else
  88. {
  89. Console.WriteLine("Liquids left: none");
  90. }
  91.  
  92.  
  93. if (items.Count > 0)
  94. {
  95. Console.WriteLine($"Physical items left: {string.Join(", ", items)}");
  96. }
  97. else
  98. {
  99. Console.WriteLine("Physical items left: none");
  100. }
  101.  
  102. foreach (var material in materialQuantity.OrderBy(m => m.Key))
  103. {
  104. Console.WriteLine($"{material.Key}: {material.Value}");
  105. }
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement