Advertisement
Aliendreamer

key revolver

Jul 26th, 2018
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8.  
  9. namespace keyRevolver
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             int costOfBullets = int.Parse(Console.ReadLine());
  16.  
  17.             int revolverSize = int.Parse(Console.ReadLine());
  18.  
  19.             int[]tokensbullets = Console.ReadLine().Split().Select(int.Parse).ToArray();
  20.             Stack<int> bullets=new Stack<int>(tokensbullets);
  21.             int[] tokensLocks = Console.ReadLine().Split().Select(int.Parse).ToArray();
  22.             Stack<int>locks=new Stack<int>(tokensLocks.Reverse());
  23.             int bounty = int.Parse(Console.ReadLine());
  24.             int count = 0;
  25.             int startBullets = bullets.Count;
  26.            
  27.             while (bullets.Count !=0 && locks.Count != 0)
  28.             {
  29.                 int bullet = bullets.Pop();
  30.                 int currentlock = locks.Pop();
  31.                 count++;
  32.                 if (bullet <= currentlock)
  33.                 {
  34.                     Console.WriteLine("Bang!");
  35.                 }
  36.                 else
  37.                 {
  38.                     Console.WriteLine("Ping!");
  39.                     locks.Push(currentlock);
  40.                 }
  41.  
  42.                 if (bullets.Count == 0)
  43.                 {
  44.                     break;
  45.                 }
  46.                 if (count == revolverSize)
  47.                 {
  48.                     Console.WriteLine("Reloading!");
  49.                     count = 0;
  50.                 }
  51.  
  52.             }
  53.  
  54.             if (locks.Count>0)
  55.             {
  56.                 Console.WriteLine($"Couldn't get through. Locks left: {locks.Count}");
  57.             }
  58.             else
  59.             {
  60.                 int bulletsLeft = bullets.Count;
  61.                 int money = bounty - (costOfBullets * (startBullets - bulletsLeft));
  62.                 Console.WriteLine($"{bulletsLeft} bullets left. Earned ${money}");
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement