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
- {
- public class StartUp
- {
- public static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- List<int> wallList = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToList();
- Stack<int> rockStack = new Stack<int>();
- for (int i = 1; i <= n; i++)
- {
- List<int> rockList = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToList();
- AddWarriors(rockStack, rockList);
- if (i % 3 == 0)
- {
- int additionalWall = int.Parse(Console.ReadLine());
- wallList.Add(additionalWall);
- }
- while (rockStack.Count > 0 && wallList.Count > 0)
- {
- int currentRock = rockStack.Pop();
- int currentWall = wallList[0];
- if (currentRock > currentWall)
- {
- currentRock -= currentWall;
- rockStack.Push(currentRock);
- wallList.RemoveAt(0);
- }
- else if (currentRock < currentWall)
- {
- currentWall -= currentRock;
- wallList[0] = currentWall;
- }
- else
- {
- wallList.RemoveAt(0);
- }
- }
- if (wallList.Count == 0)
- {
- break;
- }
- }
- PrintOutput(wallList, rockStack);
- }
- private static void PrintOutput(List<int> wallList, Stack<int> rockStack)
- {
- if (wallList.Count == 0)
- {
- Console.WriteLine($"Rocks left: {String.Join(", ", rockStack)}");
- }
- else
- {
- Console.WriteLine($"Walls left: {String.Join(", ", wallList)}");
- }
- }
- private static void AddWarriors(Stack<int> rockStack, List<int> rockList)
- {
- foreach (var war in rockList)
- {
- rockStack.Push(war);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement