Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _02.Ladybugs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int sizeOftheField = int.Parse(Console.ReadLine());
- long[] indexOfLadybugs = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
- long[] field = new long[sizeOftheField];
- for (int i = 0; i < field.Length; i++)
- {
- if (indexOfLadybugs.Contains(i))
- {
- field[i] = 1;
- }
- }
- string command = "";
- while ((command = Console.ReadLine()) != "end")
- {
- string[] splitCommand = command.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
- long index = long.Parse(splitCommand[0]);
- string commandToFly = splitCommand[1];
- long flyLenght = long.Parse(splitCommand[2]);
- if(index > field.Length - 1 || index < 0)
- {
- continue;
- }
- if (commandToFly == "left")
- {
- FlyLeft(field, index, flyLenght);
- }
- else if(commandToFly == "right")
- {
- FlyRight(field, index, flyLenght);
- }
- Console.WriteLine(String.Join(" ", field));
- }
- Console.WriteLine(String.Join(" ", field));
- }
- private static void FlyRight(long[] field, long index, long flyLenght)
- {
- if (field[index] == 1)
- {
- field[index] = 0;
- }
- else
- {
- return;
- }
- while (true)
- {
- if (index + flyLenght < 0 || index + flyLenght > field.Length -1)
- {
- return;
- }
- else if (field[index + flyLenght] == 0)
- {
- field[index+flyLenght] = 1;
- break;
- }
- else
- {
- flyLenght += flyLenght;
- }
- }
- }
- private static void FlyLeft(long[] field, long index, long flyLenght)
- {
- if (field[index] == 1)
- {
- field[index] = 0;
- }
- else
- {
- return;
- }
- while (true)
- {
- if (index - flyLenght < 0 || index - flyLenght > field.Length - 1)
- {
- return;
- }
- else if (field[index - flyLenght] == 0)
- {
- field[index - flyLenght] = 1;
- break;
- }
- else
- {
- flyLenght -= flyLenght;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment