Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<int> plates = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
- Stack<int> orcWaves = new Stack<int>();
- for (int i = 1; i <= n; i++)
- {
- orcWaves = new Stack<int>(Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray());
- if (i % 3 == 0)
- {
- int plate = int.Parse(Console.ReadLine());
- plates.Add(plate);
- }
- while (plates.Count != 0 && orcWaves.Count != 0)
- {
- int currentPlate = plates[0];
- int currentOrc = orcWaves.Pop();
- if (currentPlate < currentOrc)
- {
- currentOrc -= currentPlate;
- orcWaves.Push(currentOrc);
- plates.RemoveAt(0);
- }
- else if (currentOrc < currentPlate)
- {
- currentPlate -= currentOrc;
- plates[0] = currentPlate;
- }
- else
- {
- plates.RemoveAt(0);
- }
- }
- if (plates.Count == 0)
- {
- break;
- }
- }
- if (plates.Count == 0)
- {
- Console.WriteLine($"The orcs successfully destroyed the Gondor's defense.");
- Console.WriteLine($"Orcs left: {string.Join(", ", orcWaves)}");
- }
- else
- {
- Console.WriteLine("The people successfully repulsed the orc's attack.");
- Console.WriteLine($"Plates left: {string.Join(", ", plates)}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement