Advertisement
Guest User

Untitled

a guest
Feb 18th, 2022
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace KeyRevolver
  6. {
  7.     public static class Program
  8.     {
  9.         private static void Main(string[] args)
  10.         {
  11.             var priceBullet = int.Parse(Console.ReadLine());
  12.             var sizeOfGunBarrel = int.Parse(Console.ReadLine());
  13.             var bullets = new Stack<int>(Console.ReadLine().Split(" ").Select(int.Parse));
  14.             var locks = new Queue<int>(Console.ReadLine().Split(" ").Select(int.Parse));
  15.             var valueOfIntelligence = int.Parse(Console.ReadLine());
  16.             var usedBullets = 0;
  17.  
  18.             while (bullets.Any() && locks.Any())
  19.             {
  20.                 var currentBulletSize = bullets.Pop();
  21.                 usedBullets++;
  22.  
  23.                 if (currentBulletSize > locks.Peek())
  24.                 {
  25.                     Console.WriteLine("Ping!");
  26.                 }
  27.                 else
  28.                 {
  29.                     locks.Dequeue();
  30.                     Console.WriteLine("Bang!");
  31.                 }
  32.  
  33.                 if (usedBullets % sizeOfGunBarrel == 0 && bullets.Any())
  34.                 {
  35.                     Console.WriteLine("Reloading!");
  36.                 }
  37.             }
  38.  
  39.             if (locks.Any())
  40.             {
  41.                 Console.WriteLine($"Couldn't get through. Locks left: {locks.Count}");
  42.             }
  43.             else
  44.             {
  45.                 var profit = valueOfIntelligence - usedBullets * priceBullet;
  46.                 Console.WriteLine($"{bullets.Count} bullets left. Earned ${profit}");
  47.             }
  48.         }
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement