Advertisement
Guest User

Untitled

a guest
May 13th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class CubicArtillery
  7. {
  8.     public static void Main()
  9.     {
  10.         int capacity = int.Parse(Console.ReadLine());
  11.         Queue<string> bunkers = new Queue<string>();
  12.         Queue<int> wepons = new Queue<int>();
  13.         StringBuilder result = new StringBuilder();
  14.  
  15.         var input = Console.ReadLine().Split();
  16.  
  17.         while (!input[0].Equals("Bunker"))
  18.         {
  19.             for (int i = 0; i < input.Length; i++)
  20.             {
  21.                 if (Char.IsLetter(input[i][0]))
  22.                 {
  23.                     bunkers.Enqueue(input[i]);
  24.                 }
  25.                 else
  26.                 {
  27.                     int currentWepon = int.Parse(input[i]);
  28.                     string currentBunker = string.Empty;
  29.                     if (wepons.Sum() + currentWepon > capacity)
  30.                     {
  31.                         if (bunkers.Count > 1)
  32.                         {
  33.                             // ako bunkera nqma oryjiq napishi Empty
  34.                             if (wepons.Count > 0)
  35.                             {
  36.                                 currentBunker = bunkers.Dequeue();
  37.                                 PrintFullBunker(currentBunker, wepons, result);
  38.                             }
  39.                             if (currentWepon <= capacity)
  40.                             {
  41.                                 wepons.Enqueue(currentWepon);
  42.                             }
  43.                             else
  44.                             {
  45.                                 if (bunkers.Count > 1)
  46.                                 {
  47.                                     result.AppendLine(bunkers.Dequeue() + " -> Empty");
  48.                                 }
  49.                             }
  50.                             break;
  51.                         }
  52.                         if (bunkers.Count == 1)
  53.                         {
  54.                             //proverka izobshto tova uryjie moje li da vleze
  55.                             if (currentWepon <= capacity)
  56.                             {
  57.                                 //proveri dali moje da se sybere i zapochni da praznish za da slojish oryjieto
  58.                                 while (wepons.Sum() + currentWepon > capacity)
  59.                                 {
  60.                                     wepons.Dequeue();
  61.                                 }
  62.                                 wepons.Enqueue(currentWepon);
  63.                                 // ne trqbva da vadq bunkera ako e posleden
  64.                                 //currentBunker = bunkers.Peek();
  65.                                 //PrintFullBunker(currentBunker, wepons, result);
  66.                             }
  67.                         }
  68.                     }
  69.                     else
  70.                     {
  71.                         wepons.Enqueue(currentWepon);
  72.                     }
  73.                 }
  74.             }
  75.             input = Console.ReadLine().Split();
  76.         }
  77.         Console.WriteLine(result);
  78.     }
  79.  
  80.     private static void PrintFullBunker(string currentBunker, Queue<int> wepons, StringBuilder result)
  81.     {
  82.         result.Append(currentBunker + " -> ");
  83.         result.AppendLine(string.Join(", ", wepons));
  84.         wepons.Clear();
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement