Advertisement
Guest User

Untitled

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