Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace ladybugs10
- {
- class Program
- {
- static void Main(string[] args)
- {
- int fieldSize = int.Parse(Console.ReadLine());
- int[] ladybugIndexes = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int[] result = new int[fieldSize];
- int counter = 0;
- for (int i = 0; i < result.Length; i++)
- {
- if (counter == ladybugIndexes.Length)
- {
- break;
- }
- if (ladybugIndexes[counter] < 0)
- {
- counter++;
- i = -1;
- continue;
- }
- if (ladybugIndexes[counter] == i)
- {
- counter++;
- result[i] = 1;
- }
- }
- string input = Console.ReadLine();
- bool isWrongDirection = false;
- while (input != "end")
- {
- string[] command = input.Split(' ');
- int index = int.Parse(command[0]);
- string direction = command[1];
- int length = int.Parse(command[2]);
- for (int i = 0; i < result.Length; i++)
- {
- if (index == i && result[i] == 1)
- {
- int ladybug = i;
- switch (direction)
- {
- case "right":
- if (length < 0)
- {
- direction = "left";
- length *= -1;
- ladybug -= length;
- break;
- }
- ladybug += length;
- break;
- case "left":
- if (length < 0)
- {
- direction = "right";
- length *= -1;
- ladybug += length;
- break;
- }
- ladybug -= length;
- break;
- default: isWrongDirection = true; break;
- }
- if (isWrongDirection)
- {
- isWrongDirection = false;
- break;
- }
- if (ladybug >= result.Length || ladybug < 0)
- {
- result[index] = 0;
- if (result.Length == 0)
- {
- continue;
- }
- continue;
- }
- if (length == 0)
- {
- continue;
- }
- int iterator = i;
- if (direction == "right")
- {
- while (true)
- {
- iterator += length;
- if (iterator >= result.Length)
- {
- break;
- }
- if (ladybug == iterator && result[iterator] == 1 && iterator < result.Length)
- {
- ladybug += length;
- }
- else
- {
- break;
- }
- }
- }
- else if (direction == "left")
- {
- while (true)
- {
- iterator -= length;
- if (iterator < 0 || ladybug < 0)
- {
- break;
- }
- if (ladybug == iterator && result[iterator] == 1)
- {
- ladybug -= length;
- }
- else
- {
- break;
- }
- }
- }
- if (ladybug < 0 || ladybug >= result.Length)
- {
- result[index] = 0;
- continue;
- }
- result[ladybug] = 1;
- result[index] = 0;
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine(string.Join(' ', result));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement