Advertisement
Guest User

Cubic Artillery - 80p

a guest
Jun 20th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 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.             string input = Console.ReadLine();
  18.             while (input != "Bunker Revision")
  19.             {
  20.                 string[] tokens = input.Split(new char[] { ' ', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries);
  21.  
  22.                 foreach (var item in tokens)
  23.                 {
  24.                     if (Regex.IsMatch(item, "[a-zA-Z]"))
  25.                     {
  26.                         bunkers.Enqueue(item);
  27.                     }
  28.                     else
  29.                     {
  30.                         int weaponCapacity = int.Parse(item);
  31.  
  32.                         bool weaponContained = false;
  33.                         while (bunkers.Count > 1)
  34.                         {
  35.                             if (freeCapacity >= weaponCapacity)
  36.                             {
  37.                                 weapons.Enqueue(weaponCapacity);
  38.                                 freeCapacity -= weaponCapacity;
  39.                                 weaponContained = true;
  40.                                 break;
  41.                             }
  42.  
  43.                             if (weapons.Count == 0)
  44.                             {
  45.                                 Console.WriteLine($"{bunkers.Peek()} -> Empty");
  46.                             }
  47.                             else
  48.                             {
  49.                                 Console.WriteLine($"{bunkers.Peek()} -> {string.Join(", ", weapons)}");
  50.                             }
  51.  
  52.                             bunkers.Dequeue();
  53.                             weapons.Clear();
  54.                             freeCapacity = maxCapacity;
  55.                         }
  56.  
  57.                         if (!weaponContained && bunkers.Count == 1)
  58.                         {
  59.                             if (maxCapacity >= weaponCapacity)
  60.                             {
  61.                                 if (freeCapacity < weaponCapacity)
  62.                                 {
  63.                                     while (freeCapacity < weaponCapacity)
  64.                                     {
  65.                                         int removedWeapon = weapons.Dequeue();
  66.                                         freeCapacity += removedWeapon;
  67.                                     }
  68.                                 }
  69.  
  70.                                 weapons.Enqueue(weaponCapacity);
  71.                                 freeCapacity -= weaponCapacity;
  72.                             }
  73.                         }
  74.                     }
  75.  
  76.                 }
  77.  
  78.                 input = Console.ReadLine();
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement