Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Trojan_Invasion
- {
- class Program
- {
- static void Main(string[] args)
- {
- int waves = int.Parse(Console.ReadLine());
- bool IsTrojanWin = false;
- Stack<int> wariors = new Stack<int>(); //push,Pop,Peek
- int[] plateTemp = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- List<int> plates = new List<int>(plateTemp);
- for (int i = 1; i <= waves; i++)
- {
- if (i % 3 == 0)
- {
- //int addNewPlate = 0;
- int[] warriorTemp = Console.ReadLine().Split().Select(int.Parse).ToArray();
- for (int e = 0; e < warriorTemp.Length; e++)
- {
- wariors.Push(warriorTemp[e]);
- }
- int[] boom = Console.ReadLine().Split().Select(int.Parse).ToArray();
- // plates.IndexOf(addNewPlate, 0);
- plates.Add(boom[0]);
- }
- else
- {
- int[] warriorTemp = Console.ReadLine().Split().Select(int.Parse).ToArray();
- for (int j = 0; j < warriorTemp.Length; j++)
- {
- wariors.Push(warriorTemp[j]);
- }
- }
- while (plates.Count > 0 && wariors.Count > 0)
- {
- if (plates[0] > wariors.Peek())
- {
- plates[0] = plates[0] - wariors.Peek();
- wariors.Pop();
- }
- else if (wariors.Peek() > plates[0])
- {
- wariors.Push(wariors.Pop() - plates[0]);
- plates.RemoveAt(0);
- }
- else if (wariors.Peek() == plates[0])
- {
- wariors.Pop();
- plates.RemoveAt(0);
- }
- if (wariors.Count == 0)
- {
- break;
- }
- if (plates.Count == 0)
- {
- Console.WriteLine("The Trojans successfully destroyed the Spartan defense.");
- Console.WriteLine($"Warriors left: {string.Join(", ", wariors)}");
- IsTrojanWin = true;
- break;
- }
- }
- if (IsTrojanWin)
- {
- break;
- }
- if (plates.Count == 0 && wariors.Count > 0 && i == waves)
- {
- Console.WriteLine("The Trojans successfully destroyed the Spartan defense.");
- Console.WriteLine($"Warriors left: {string.Join(", ", wariors)}");
- break;
- }
- else if (wariors.Count == 0 && plates.Count > 0 && i == waves)
- {
- Console.WriteLine("The Spartans successfully repulsed the Trojan attack.");
- Console.WriteLine($"Plates left: {string.Join(", ", plates)}");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment