bullit3189

Cubic Artillery

Jun 11th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. namespace Problem_1
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text.RegularExpressions;
  6.  
  7. class Startup
  8. {
  9. static void Main()
  10. {
  11. int maxCapacity = int.Parse(Console.ReadLine());
  12.  
  13. var bunkers = new Queue<string>();
  14. var weapons = new Queue<int>();
  15. int freeCapacity = maxCapacity;
  16.  
  17. Regex rgx = new Regex("[a-zA-Z]");
  18.  
  19. string input = Console.ReadLine();
  20. while (input != "Bunker Revision")
  21. {
  22. string[] tokens = input.Split(new char[] { ' ', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries);
  23.  
  24. foreach (var item in tokens)
  25. {
  26. if (rgx.IsMatch(item))
  27. {
  28. bunkers.Enqueue(item);
  29. }
  30. else
  31. {
  32. int weaponCapacity = int.Parse(item);
  33.  
  34. bool weaponContained = false;
  35. while (bunkers.Count > 1)
  36. {
  37. if (freeCapacity >= weaponCapacity)
  38. {
  39. weapons.Enqueue(weaponCapacity);
  40. freeCapacity -= weaponCapacity;
  41. weaponContained = true;
  42. break;
  43. }
  44.  
  45. if (weapons.Count == 0)
  46. {
  47. Console.WriteLine($"{bunkers.Peek()} -> Empty");
  48. }
  49. else
  50. {
  51. Console.WriteLine($"{bunkers.Peek()} -> {string.Join(", ", weapons)}");
  52. }
  53.  
  54. bunkers.Dequeue();
  55. weapons.Clear();
  56. freeCapacity = maxCapacity;
  57. }
  58.  
  59. if (!weaponContained && bunkers.Count == 1)
  60. {
  61. if (maxCapacity >= weaponCapacity)
  62. {
  63. if (freeCapacity < weaponCapacity)
  64. {
  65. while (freeCapacity < weaponCapacity)
  66. {
  67. int removedWeapon = weapons.Dequeue();
  68. freeCapacity += removedWeapon;
  69. }
  70. }
  71.  
  72. weapons.Enqueue(weaponCapacity);
  73. freeCapacity -= weaponCapacity;
  74. }
  75. }
  76. }
  77.  
  78. }
  79.  
  80. input = Console.ReadLine();
  81. }
  82. }
  83. }
  84. }
Add Comment
Please, Sign In to add comment