Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace LadyBugs
- {
- class Program
- {
- //public static bool IsArrayEmpty(int[] field)
- //{
- // int sum = 0;
- // for (int i = 0; i < field.Length; i++)
- // {
- // sum += field[i];
- // }
- // if (sum == 0)
- // {
- // return true;
- // }
- // return false;
- //}
- static void Main()
- {
- ushort size = ushort.Parse(Console.ReadLine());
- int[] startIndexes = Console
- .ReadLine()
- .Split()
- .Select(int.Parse).
- ToArray();
- int[] field = new int[size];
- foreach (int index in startIndexes)
- {
- if (index > size - 1 || index < 0)
- {
- continue;
- }
- field[index] = 1;
- }
- string commandAsString = "";
- while ((commandAsString = Console.ReadLine()) != "end")
- {
- string[] command = commandAsString.Split();
- string direction = command[1];
- int startIndex = int.Parse(command[0]);
- int flyLenght = int.Parse(command[2]);
- int landIndex = 0;
- if (startIndex < 0 || startIndex >= size || field[startIndex] == 0)
- {
- continue;
- }
- if (direction == "left")
- {
- landIndex = startIndex - flyLenght;
- while (landIndex >= 0)
- {
- if (field[landIndex] == 0)
- {
- field[landIndex] = 1;
- break;
- }
- landIndex -= flyLenght;
- }
- }
- else if (direction == "right")
- {
- landIndex = startIndex + flyLenght;
- while (landIndex < size)
- {
- if (field[landIndex] == 0)
- {
- field[landIndex] = 1;
- break;
- }
- landIndex += flyLenght;
- }
- }
- field[startIndex] = 0;
- //if (IsArrayEmpty(field))
- //{
- // break;
- //}
- }
- string output = string.Join(" ", field);
- Console.WriteLine(output);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement