Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace LadyBugs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int fieldSize = int.Parse(Console.ReadLine());
- int[] indexes = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int[] fieldPositions = new int[fieldSize];
- int commandsCount = 0;
- for (int i = 0; i < fieldSize; i++)
- {
- for (int j = 0; j < indexes.Length; j++)
- {
- if (indexes[j] == i)
- {
- fieldPositions[i] = 1;
- }
- }
- }
- bool isEnd = false;
- while (!isEnd && commandsCount <= 100)
- {
- string input = Console.ReadLine();
- if (input == "end")
- {
- isEnd = true;
- continue;
- }
- string[] command = input.Split().ToArray();
- commandsCount++;
- int currLadybugIndex = int.Parse(command[0]);
- string direction = command[1];
- int flyLength = int.Parse(command[2]);
- if (flyLength < 0)
- {
- if (direction == "right")
- {
- direction = "left";
- }
- if (direction == "left")
- {
- direction = "right";
- }
- flyLength = Math.Abs(flyLength);
- }
- bool ladybugValidIndex = false;
- for (int i = 0; i < fieldSize; i++)
- {
- if (currLadybugIndex == i && fieldPositions[currLadybugIndex] == 1)
- {
- ladybugValidIndex = true;
- break;
- }
- }
- if (ladybugValidIndex == true)
- {
- if (direction == "right")
- {
- fieldPositions[currLadybugIndex] = 0;
- for (int i = currLadybugIndex + flyLength; i < fieldPositions.Length; i++)
- {
- if (fieldPositions[i] == 0)
- {
- fieldPositions[i] = 1;
- break;
- }
- }
- }
- else if (direction == "left")
- {
- fieldPositions[currLadybugIndex] = 0;
- for (int i = currLadybugIndex - flyLength; i >= 0; i--)
- {
- if (fieldPositions[i] == 0)
- {
- fieldPositions[i] = 1;
- break;
- }
- }
- }
- else
- {
- fieldPositions[currLadybugIndex] = 1;
- }
- }
- }
- Console.WriteLine(string.Join(' ', fieldPositions));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement