Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02.Version2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int countOfWaves = int.Parse(Console.ReadLine());
- int[] platesElements = Console.ReadLine().Split().Select(int.Parse).ToArray();
- Stack<int> plates = new Stack<int>(platesElements.Reverse());
- Stack<int> warriors = new Stack<int>();
- for (int i = 1; i <= countOfWaves; i++)
- {
- int[] warriorPower = Console.ReadLine().Split().Select(int.Parse).ToArray();
- if (i % 3 == 0)
- {
- int extraPlate = int.Parse(Console.ReadLine());
- plates.Push(extraPlate);
- }
- foreach (var warrior in warriorPower)
- {
- warriors.Push(warrior);
- }
- while (warriors.Any() && plates.Any())
- {
- int currentPlate = plates.Peek();
- int currentWarrior = warriors.Peek();
- if (currentPlate == currentWarrior)
- {
- plates.Pop();
- warriors.Pop();
- }
- else if (currentWarrior > currentPlate)
- {
- currentWarrior -= currentPlate;
- warriors.Pop();
- warriors.Push(currentWarrior);
- plates.Pop();
- continue;
- }
- else if (currentPlate > currentWarrior)
- {
- currentPlate -= currentWarrior;
- plates.Pop();
- plates.Push(currentPlate);
- warriors.Pop();
- continue;
- }
- }
- if (!plates.Any())
- {
- break;
- }
- }
- if (warriors.Count > 0)
- {
- Console.WriteLine("The Trojans successfully destroyed the Spartan defense.");
- Console.WriteLine($"Warriors left: " + string.Join(", ", warriors));
- }
- else
- {
- Console.WriteLine("The Spartans successfully repulsed the Trojan attack.");
- Console.WriteLine($"Plates left: " + string.Join(", ", plates));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment