Advertisement
Guest User

trojan

a guest
Oct 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Trojan_Invasion
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Stack<int> warriors = new Stack<int>();
  12.  
  13.             int numberWaves = int.Parse(Console.ReadLine());
  14.             Queue<int> plates = new Queue<int>(Console.ReadLine()
  15.                .Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
  16.  
  17.             int plate = 0;
  18.             for (int i = 1; i <= numberWaves; i++)
  19.             {
  20.                 if (plates.Count == 0)
  21.                 {
  22.                     break;
  23.                 }
  24.  
  25.                 int[] newWave = Console.ReadLine()
  26.                .Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  27.  
  28.                 for (int t = 0; t < newWave.Length; t++)
  29.                 {
  30.                     warriors.Push(newWave[t]);
  31.                 }
  32.  
  33.                 if (i % 3 == 0)
  34.                 {
  35.                     plates.Enqueue(int.Parse(Console.ReadLine()));
  36.                 }
  37.  
  38.                 while (warriors.Any() && plates.Any())
  39.                 {
  40.                     int warrior = warriors.Peek();
  41.                     if (plate == 0)
  42.                     {
  43.                         plate = plates.Peek();
  44.                     }
  45.  
  46.                     if (warrior == plate)
  47.                     {
  48.                         warriors.Pop();
  49.                         plates.Dequeue();
  50.                         plate = 0;
  51.                     }
  52.                     else if (warrior > plate)
  53.                     {
  54.                         warrior -= plate;
  55.                         warriors.Pop();
  56.                         warriors.Push(warrior);
  57.                         plates.Dequeue();
  58.                         plate = 0;
  59.                     }
  60.                     else if (plate > warrior)
  61.                     {
  62.                         warriors.Pop();
  63.                         plate -= warrior;
  64.                     }
  65.                 }
  66.             }
  67.  
  68.             if (plates.Count == 0)
  69.             {
  70.                 Console.WriteLine("The Trojans successfully destroyed the Spartan defense.");
  71.                 Console.WriteLine($"Warriors left: {string.Join(", ", warriors)}");
  72.             }
  73.             else
  74.             {
  75.                 Console.WriteLine("The Spartans successfully repulsed the Trojan attack.");
  76.                 Console.WriteLine($"Plates left: {string.Join(", ", plates)}");
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement