Advertisement
Danny_Berova

01.KeyRevolver80/100

Feb 11th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _01.Problem
  7. {
  8.     public class ProblemOne
  9.     {
  10.         public static void Main()
  11.         {
  12.             var priceOfBullet = int.Parse(Console.ReadLine());
  13.             var sizeOfBarrel = int.Parse(Console.ReadLine());
  14.             var bullets = new Queue<long>(Console.ReadLine().Split().Select(long.Parse).Reverse());
  15.             var locks = new Queue<long>(Console.ReadLine().Split().Select(long.Parse));
  16.             var budget = int.Parse(Console.ReadLine());
  17.  
  18.             while (bullets.Count > 0 && locks.Count > 0)
  19.             {
  20.                 for (int i = 0; i < sizeOfBarrel; i++)
  21.                 {
  22.                     if (bullets.Count != 0 && locks.Count != 0)
  23.                     {
  24.                         var currentBullet = bullets.Dequeue();
  25.                         var currentLock = locks.Peek();
  26.  
  27.                         if (currentBullet > currentLock)
  28.                         {
  29.                             Console.WriteLine("Ping!");
  30.                             budget -= priceOfBullet;
  31.                         }
  32.                         else
  33.                         {
  34.                             Console.WriteLine($"Bang!");
  35.                             budget -= priceOfBullet;
  36.                             locks.Dequeue();
  37.                         }
  38.                     }
  39.                     else
  40.                     {
  41.                         break;
  42.                     }
  43.                 }
  44.  
  45.                 if (bullets.Count > 0)
  46.                 {
  47.                     Console.WriteLine("Reloading!");
  48.                 }
  49.  
  50.             }
  51.  
  52.             if (locks.Count > 0)
  53.             {
  54.                 Console.WriteLine($"Couldn't get through. Locks left: {locks.Count}");
  55.             }
  56.             else
  57.             {
  58.                 Console.WriteLine($"{bullets.Count} bullets left. Earned ${budget}");
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement