Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace LadyBug
- {
- class Program
- {
- static void mooveRight(int[] arr, int index, int steps)
- {
- if ((index + steps) < arr.Length)
- {
- arr[index] = 0;
- for (int i = index+steps; i < arr.Length ; i += steps)
- {
- if (arr[i] == 0)
- {
- arr[i] = 1;
- break;
- }
- }
- }
- else arr[index] = 0;
- }
- static void mooveLeft(int[] arr, int index, int steps)
- {
- if ((index - steps) >=0)
- {
- arr[index] = 0;
- for (int i = index-steps; i > -1; i -= steps)
- {
- if (arr[i] ==0)
- {
- arr[i] = 1;
- break;
- }
- }
- }
- else arr[index] = 0;
- }
- static void Main(string[] args)
- {
- int sizeOfField = int.Parse(Console.ReadLine());
- int[] field = new int[sizeOfField];
- for (int i = 0; i < field.Length; i++)
- {
- field[i] = 0;
- }
- string indexesString = Console.ReadLine();
- int[] arr = indexesString
- .Split(' ')
- .Select(int.Parse)
- .ToArray();
- for (int i = 0; i < arr.Length; i++)
- {
- if(arr[i]>=sizeOfField)
- {
- arr[i] = arr[i] % sizeOfField;
- }
- field[arr[i]] = 1;
- }
- string lineInput = string.Empty;
- while ((lineInput = Console.ReadLine()) != "end")
- {
- string[] input = lineInput.Split().ToArray();
- int index = int.Parse(input[0]);
- string direction = input[1];
- int flyLength = int.Parse(input[2]);
- if (index >= 0 && index < sizeOfField&& field[index]==1)
- {
- if (flyLength < 0 && direction == "left")
- {
- flyLength = Math.Abs(flyLength);
- mooveRight(field, index, flyLength);
- }
- if (flyLength < 0 && direction == "right")
- {
- flyLength = Math.Abs(flyLength);
- mooveLeft(field, index, flyLength);
- }
- if (direction == "right" && flyLength > 0)
- {
- mooveRight(field, index, flyLength);
- }
- if (direction == "left" && flyLength > 0)
- {
- mooveLeft(field, index, flyLength);
- }
- }
- }
- Console.WriteLine(string.Join(' ', field));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement