silvana1303

bombs / methods

Oct 21st, 2020
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace zadacha
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             /* •Datura Bombs: 40
  12.                •Cherry Bombs: 60
  13.                •Smoke Decoy Bombs: 120*/
  14.  
  15.             int datura = 0;
  16.             int cherry = 0;
  17.             int smoke = 0;
  18.             bool pouch = false;
  19.  
  20.            
  21.  
  22.             int[] first = Console.ReadLine().Split(", ").Select(int.Parse).ToArray();
  23.             int[] second = Console.ReadLine().Split(", ").Select(int.Parse).ToArray();
  24.  
  25.             Queue<int> effect = new Queue<int>(first);
  26.             Stack<int> casing = new Stack<int>(second);
  27.  
  28.             while (effect.Any() && casing.Any())
  29.             {
  30.                 if (Pouch(datura, cherry, smoke, ref pouch)) break;
  31.  
  32.                 datura = BombMaking(effect, casing, datura, ref cherry, ref smoke);
  33.             }
  34.  
  35.             PouchMaking(pouch);
  36.  
  37.             EffectsOutput(effect);
  38.  
  39.             CasingsOutput(casing);
  40.  
  41.             Console.WriteLine($"Cherry Bombs: {cherry}");
  42.             Console.WriteLine($"Datura Bombs: {datura}");
  43.             Console.WriteLine($"Smoke Decoy Bombs: {smoke}");
  44.  
  45.         }
  46.  
  47.         private static void CasingsOutput(Stack<int> casing)
  48.         {
  49.             if (casing.Any())
  50.             {
  51.                 Console.WriteLine($"Bomb Casings: {string.Join(", ", casing)}");
  52.             }
  53.             else
  54.             {
  55.                 Console.WriteLine("Bomb Casings: empty");
  56.             }
  57.         }
  58.  
  59.         private static void EffectsOutput(Queue<int> effect)
  60.         {
  61.             if (effect.Any())
  62.             {
  63.                 Console.WriteLine($"Bomb Effects: {string.Join(", ", effect)}");
  64.             }
  65.             else
  66.             {
  67.                 Console.WriteLine("Bomb Effects: empty");
  68.             }
  69.         }
  70.  
  71.         private static void PouchMaking(bool pouch)
  72.         {
  73.             if (pouch)
  74.             {
  75.                 Console.WriteLine("Bene! You have successfully filled the bomb pouch!");
  76.             }
  77.             else
  78.             {
  79.                 Console.WriteLine("You don't have enough materials to fill the bomb pouch.");
  80.             }
  81.         }
  82.  
  83.         private static int BombMaking(Queue<int> effect, Stack<int> casing, int datura, ref int cherry, ref int smoke)
  84.         {
  85.             if (effect.Peek() + casing.Peek() == 40)
  86.             {
  87.                 datura++;
  88.                 effect.Dequeue();
  89.                 casing.Pop();
  90.             }
  91.             else if (effect.Peek() + casing.Peek() == 60)
  92.             {
  93.                 cherry++;
  94.                 effect.Dequeue();
  95.                 casing.Pop();
  96.             }
  97.             else if (effect.Peek() + casing.Peek() == 120)
  98.             {
  99.                 smoke++;
  100.                 effect.Dequeue();
  101.                 casing.Pop();
  102.             }
  103.             else
  104.             {
  105.                 casing.Push(casing.Pop() - 5);
  106.             }
  107.  
  108.             return datura;
  109.         }
  110.  
  111.         private static bool Pouch(int datura, int cherry, int smoke, ref bool pouch)
  112.         {
  113.             if (datura >= 3 && cherry >= 3 && smoke >= 3)
  114.             {
  115.                 pouch = true;
  116.                 return true;
  117.             }
  118.  
  119.             return false;
  120.         }
  121.     }
  122. }
  123.  
Advertisement
Add Comment
Please, Sign In to add comment