Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Exam_23062019
- {
- class Program
- {
- static void Main(string[] args)
- {
- Queue<int> chemicalLiquids = new Queue<int>(Console.ReadLine()
- .Split()
- .Select(int.Parse));
- Stack<int> physicalItems = new Stack<int>(Console.ReadLine()
- .Split()
- .Select(int.Parse));
- int glass = 25;
- int aluminium = 50;
- int lithium = 75;
- int carbonFiber = 100;
- //bool isSuccesful = false;
- var craftedItems = new Dictionary<string, int>
- {
- { "Glass", 0 },
- { "Aluminium", 0 },
- { "Lithium", 0 },
- { "Carbon fiber", 0 }
- };
- while (true)
- {
- if (chemicalLiquids.Count == 0 || physicalItems.Count == 0 )
- {
- break;
- }
- int currentSum = chemicalLiquids.Peek() + physicalItems.Peek();
- if (currentSum == glass)
- {
- craftedItems["Glass"]++;
- chemicalLiquids.Dequeue();
- physicalItems.Pop();
- }
- else if (currentSum == aluminium)
- {
- craftedItems["Aluminium"]++;
- chemicalLiquids.Dequeue();
- physicalItems.Pop();
- }
- else if (currentSum == lithium)
- {
- craftedItems["Lithium"]++;
- chemicalLiquids.Dequeue();
- physicalItems.Pop();
- }
- else if (currentSum == carbonFiber)
- {
- craftedItems["Carbon fiber"]++;
- chemicalLiquids.Dequeue();
- physicalItems.Pop();
- }
- else
- {
- chemicalLiquids.Dequeue();
- int increasedValue = physicalItems.Peek() + 3;
- physicalItems.Pop();
- physicalItems.Push(increasedValue);
- }
- }
- if (craftedItems["Glass"] > 0
- && craftedItems["Aluminium"] > 0
- && craftedItems["Lithium"] > 0
- && craftedItems["Carbon fiber"] > 0)
- {
- Console.WriteLine("Wohoo! You succeeded in building the spaceship!");
- }
- else
- {
- Console.WriteLine("Ugh, what a pity! You didn't have enough materials to build the spaceship.");
- }
- if (chemicalLiquids.Count <= 0)
- {
- Console.WriteLine("Liquids left: none");
- }
- else
- {
- Console.WriteLine($"Liquids left: {string.Join(", ", chemicalLiquids)}");
- }
- if (physicalItems.Count <= 0)
- {
- Console.WriteLine("Physical items left: none");
- }
- else
- {
- Console.WriteLine($"Physical items left: {string.Join(", ", physicalItems)}");
- }
- foreach (var item in craftedItems.OrderBy(x => x.Key))
- {
- Console.WriteLine($"{item.Key}: {item.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement