Advertisement
bullit3189

Key Revolver

Jun 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Numerics;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. int bulletPrice = int.Parse(Console.ReadLine());
  12. int barrelSize = int.Parse(Console.ReadLine());
  13. int[] bulletsInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14. int[] locksInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
  15. int money = int.Parse(Console.ReadLine());
  16.  
  17. Stack<int>bullets = new Stack<int>(bulletsInput);
  18. Queue<int>locks = new Queue<int>(locksInput);
  19.  
  20. int allBullets = bullets.Count;
  21.  
  22. int currShot =0;
  23.  
  24. while(bullets.Any() && locks.Any())
  25. {
  26. int currBullet = bullets.Pop();
  27. int currLock = locks.Peek();
  28.  
  29. if(currBullet<=currLock)
  30. {
  31. Console.WriteLine("Bang!");
  32. locks.Dequeue();
  33. }
  34. else
  35. {
  36. Console.WriteLine("Ping!");
  37. }
  38.  
  39. currShot++;
  40.  
  41. if(currShot==barrelSize && bullets.Count>0)
  42. {
  43. Console.WriteLine("Reloading!");
  44. currShot=0;
  45. }
  46. }
  47.  
  48. if(locks.Any())
  49. {
  50. Console.WriteLine("Couldn't get through. Locks left: {0}",locks.Count);
  51. }
  52. else
  53. {
  54. int bulletsUsed = allBullets - bullets.Count;
  55. int moneyUsed = bulletsUsed * bulletPrice;
  56. int moneyLeft = money - moneyUsed;
  57.  
  58. Console.WriteLine("{0} bullets left. Earned ${1}",bullets.Count,moneyLeft);
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement