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