alexbancheva

Bombs_Exam_28June2020

Jun 28th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.09 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace Bombs_CAdvancedExam_28June2020
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.             var inputBombEffects = Console.ReadLine();
  14.             Queue<int> bombEffects = new Queue<int>(inputBombEffects.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
  15.             bool flagNegative = false;
  16.  
  17.             foreach (var item in bombEffects)
  18.             {
  19.  
  20.                 if (item >= 0 && item <= 120)
  21.                 {
  22.                     flagNegative = false;
  23.                 }
  24.                 else
  25.                 {
  26.                     flagNegative = true;
  27.                 }
  28.             }
  29.  
  30.  
  31.             if (!flagNegative)
  32.             {
  33.                 var inputBombCasing = Console.ReadLine();
  34.                 Stack<int> bombCasing = new Stack<int>(inputBombCasing.Split(",", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
  35.                 bool flagNegativeCasing = false;
  36.  
  37.                 foreach (var item in bombCasing)
  38.                 {
  39.  
  40.                     if (item >= 0 && item <= 120)
  41.                     {
  42.                         flagNegativeCasing = false;
  43.                     }
  44.                     else
  45.                     {
  46.                         flagNegativeCasing = true;
  47.                     }
  48.                 }
  49.  
  50.                 Dictionary<string, int> bombs = new Dictionary<string, int>();
  51.               //  bombs.Add("Datura Bombs", 0);
  52.  
  53.  
  54.                 int sum = 0;
  55.  
  56.                 bool flag = false;
  57.  
  58.                 if (!flagNegativeCasing)
  59.                 {
  60.                     while (bombCasing.Any() && bombEffects.Any())
  61.                     {
  62.  
  63.                         var currentCasing = bombCasing.Peek();
  64.                         var currentEffect = bombEffects.Peek();
  65.  
  66.  
  67.                         sum = currentEffect + currentCasing;
  68.  
  69.                         if (sum == 40 || sum == 60 || sum == 120)
  70.                         {
  71.                             if (sum == 40)
  72.                             {
  73.                                 if (!bombs.ContainsKey("Datura Bombs"))
  74.                                 {
  75.                                     bombs.Add("Datura Bombs", 0);
  76.                                 }
  77.                                 bombs["Datura Bombs"]++;
  78.                             }
  79.                             else if (sum == 60)
  80.                             {
  81.                                 if (!bombs.ContainsKey("Cherry Bombs"))
  82.                                 {
  83.                                     bombs.Add("Cherry Bombs", 0);
  84.                                 }
  85.                                 bombs["Cherry Bombs"]++;
  86.                             }
  87.                             else if (sum == 120)
  88.                             {
  89.                                 if (!bombs.ContainsKey("Smoke Decoy Bombs"))
  90.                                 {
  91.                                     bombs.Add("Smoke Decoy Bombs", 0);
  92.                                 }
  93.                                 bombs["Smoke Decoy Bombs"]++;
  94.                             }
  95.                             bombCasing.Pop();
  96.                             bombEffects.Dequeue();
  97.                         }
  98.                         else
  99.                         {
  100.                             bombCasing.Push(bombCasing.Pop() - 5);
  101.                         }
  102.  
  103.                         if (bombs.ContainsKey("Datura Bombs") && bombs.ContainsKey("Cherry Bombs") && bombs.ContainsKey("Smoke Decoy Bombs"))
  104.                         {
  105.                             if (bombs["Datura Bombs"] >= 3 && bombs["Cherry Bombs"] >= 3 && bombs["Smoke Decoy Bombs"] >= 3)
  106.                             {
  107.                                 Console.WriteLine("Bene! You have successfully filled the bomb pouch!");
  108.                                 flag = true;
  109.                                 break;
  110.                             }
  111.                         }
  112.  
  113.                     }
  114.  
  115.                     if (!flag)
  116.                     {
  117.                         Console.WriteLine("You don't have enough materials to fill the bomb pouch.");
  118.                     }
  119.  
  120.  
  121.                     if (bombEffects.Count == 0)
  122.                     {
  123.                         Console.WriteLine("Bomb Effects: empty");
  124.                     }
  125.                     else
  126.                     {
  127.                         Console.WriteLine($"Bomb Effects: {string.Join(", ", bombEffects)}");
  128.                     }
  129.  
  130.                     if (bombCasing.Count == 0)
  131.                     {
  132.                         Console.WriteLine("Bomb Casings: empty");
  133.                     }
  134.                     else
  135.                     {
  136.                         Console.WriteLine($"Bomb Casings: {string.Join(", ", bombCasing)}");
  137.                     }
  138.  
  139.                     foreach (var bomb in bombs.OrderBy(k => k.Key))
  140.                     {
  141.                         Console.WriteLine($"{bomb.Key}: {bomb.Value}");
  142.                     }
  143.                 }
  144.             }
  145.         }
  146.     }
  147. }
Add Comment
Please, Sign In to add comment