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