Advertisement
gabi11

C# Adv. Exam (23072019) - 01. Spaceship Crafting

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