Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Numerics;
- namespace Ladybugs_Fly
- {
- class Program
- {
- static void Main(string[] args)
- {
- int fieldSize = int.Parse(Console.ReadLine());
- long[] initialIndexes = Console.ReadLine().Split().Select(long.Parse).ToArray();
- long[] ladybugsPositions = new long[fieldSize];
- for (long i = 0; i < fieldSize; i++)
- {
- for (long m = 0; m < initialIndexes.Length; m++)
- {
- if (initialIndexes.Contains(i))
- {
- ladybugsPositions[i] = 1;
- }
- }
- }
- string input = Console.ReadLine();
- while (input != "end")
- {
- string[] command = input.Split(" ");
- long currentLadybugIndex = long.Parse(command[0]);
- string direction = command[1];
- long flyLength = long.Parse(command[2]);
- if (fieldSize > 0 && currentLadybugIndex < ladybugsPositions.Length && ladybugsPositions[currentLadybugIndex] == 1)
- {
- ladybugsPositions[currentLadybugIndex] = 0;
- if (direction == "right")
- {
- if (currentLadybugIndex + flyLength < ladybugsPositions.Length)
- {
- while (ladybugsPositions[currentLadybugIndex + flyLength] != 0
- && currentLadybugIndex + flyLength < ladybugsPositions.Length - 1)
- {
- currentLadybugIndex += flyLength;
- }
- if (ladybugsPositions[currentLadybugIndex + flyLength] == 0)
- {
- ladybugsPositions[currentLadybugIndex + flyLength] = 1;
- }
- }
- }
- else if (direction == "left")
- {
- if (currentLadybugIndex - flyLength >= 0 && currentLadybugIndex - flyLength < ladybugsPositions.Length)
- {
- while (ladybugsPositions[currentLadybugIndex - flyLength] != 0
- && currentLadybugIndex - flyLength >= 0
- && currentLadybugIndex - flyLength < ladybugsPositions.Length - 1)
- {
- currentLadybugIndex -= flyLength;
- }
- if (ladybugsPositions[currentLadybugIndex - flyLength] == 0)
- {
- ladybugsPositions[currentLadybugIndex - flyLength] = 1;
- }
- }
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine(string.Join(" ", ladybugsPositions));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment