Advertisement
Guest User

Cubic Artillery - 100p

a guest
Jun 20th, 2016
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.95 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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement