Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Channels;
- namespace _01._Bombs
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Input
- // • On the first line, you will receive the integers representing the bomb effects, separated by ", ".
- // • On the second line, you will receive the integers representing the bomb casing, separated by ", ".
- int[] bombEffects = ReadInput();
- int[] bombCasing = ReadInput();
- Queue<int> bombEffectInQueue = new Queue<int>(bombEffects);
- Stack<int> bombCasingStack = new Stack<int>(bombCasing);
- Dictionary<string, int> bombPouch = new Dictionary<string, int>()
- {
- {"Datura Bombs", 0},
- {"Cherry Bombs", 0},
- {"Smoke Decoy Bombs", 0}
- };
- bool isFilledBombPouch = false;
- //You need to stop combining when you have no more bomb effects or bomb casings, or you successfully filled the bomb pouch
- while (bombEffectInQueue.Count > 0 && bombCasingStack.Count > 0)
- {
- int currBombEffect = bombEffectInQueue.Peek();
- int currBombCase = bombCasingStack.Peek();
- CheckBombCoincidence(currBombEffect, currBombCase, bombPouch, bombCasingStack, bombEffectInQueue);
- if (bombPouch.Count == 3)
- {
- if (IsFilledBombPouch(bombPouch))
- {
- isFilledBombPouch = true;
- break;
- }
- }
- }
- Console.WriteLine(isFilledBombPouch ? "Bene! You have successfully filled the bomb pouch!" :
- "You don't have enough materials to fill the bomb pouch.");
- Console.WriteLine(bombEffectInQueue.Count > 0
- ? $"Bomb Effects: {string.Join(", ", bombEffectInQueue)}"
- : "Bomb Effects: empty");
- Console.WriteLine(bombCasingStack.Count > 0 ? $"Bomb Casings: {string.Join(", ", bombCasingStack)}" :
- "Bomb Casings: empty");
- foreach (var currentBomb in bombPouch.OrderBy(n => n.Key))
- {
- Console.WriteLine($"{currentBomb.Key}: {currentBomb.Value}");
- }
- }
- private static void CheckBombCoincidence(int currBombEffect, int currBombCase, Dictionary<string, int> bombPouch,
- Stack<int> bombCasingStack, Queue<int> bombEffectInQueue)
- {
- int sumBombs = currBombEffect + currBombCase;
- switch (sumBombs)
- {
- case 40:
- bombPouch["Datura Bombs"] += 1;
- bombCasingStack.Pop();
- bombEffectInQueue.Dequeue();
- break;
- case 60:
- bombPouch["Cherry Bombs"] += 1;
- bombCasingStack.Pop();
- bombEffectInQueue.Dequeue();
- break;
- case 120:
- bombPouch["Smoke Decoy Bombs"] += 1;
- bombCasingStack.Pop();
- bombEffectInQueue.Dequeue();
- break;
- default:
- bombCasingStack.Pop();
- bombCasingStack.Push(currBombCase - 5);
- break;
- }
- }
- public static int[] ReadInput()
- {
- int[] input = Console.ReadLine()
- .Split(", ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- return input;
- }
- private static bool IsFilledBombPouch(Dictionary<string, int> bombPouch)
- {
- bool isFilled = false;
- foreach (var currentBomb in bombPouch)
- {
- if (currentBomb.Value >= 3)
- {
- isFilled = true;
- }
- else
- {
- isFilled = false;
- break;
- }
- }
- return isFilled;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement