Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Catapult_Attack
- {
- class Program
- {
- static void Main()
- {
- var pilesCount = int.Parse(Console.ReadLine());
- var wallsInput = Console
- .ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- var walls = new Queue<int>(wallsInput);
- var rocks = new Stack<int>();
- for (int i = 1; i <= pilesCount; i++)
- {
- var curPile = Console
- .ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToList();
- if (!walls.Any())
- {
- Console.WriteLine($"Rocks left: {string.Join(", ", rocks)}");
- break;
- }
- if (i % 3 == 0)
- {
- walls.Enqueue(int.Parse(Console.ReadLine()));
- }
- foreach (var curRock in curPile)
- {
- rocks.Push(curRock);
- }
- while (rocks.Any() && walls.Any())
- {
- var rock = rocks.Pop();
- var wall = walls.Dequeue();
- if (rock > wall)
- {
- rocks.Push(rock - wall);
- }
- else if (rock < wall)
- {
- walls.Enqueue(wall - rock);
- for (int j = 0; j < walls.Count - 1; j++)
- {
- walls.Enqueue(walls.Dequeue());
- }
- }
- }
- }
- if (!rocks.Any())
- {
- Console.WriteLine($"Walls left: {string.Join(", ", walls)}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement