Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _2._Ladybugs
- {
- class Program
- {
- static void Main(string[] args)
- {
- long[] fieldSize = new long[long.Parse(Console.ReadLine().Trim())];
- long[] indexesWhereTheBugsAre = Console.ReadLine().
- Split().
- Select(long.Parse).ToArray();
- for (int i = 0; i < fieldSize.Length; i++)
- {
- for (int j = 0; j < indexesWhereTheBugsAre.Length; j++)
- {
- if (i == indexesWhereTheBugsAre[j])
- {
- fieldSize[i] = 1;
- }
- }
- }
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end")
- {
- break;
- }
- string[] SplitedInput = input.Trim().Split().ToArray();
- int ladyBugIndex = int.Parse(SplitedInput[0]);
- string directory = SplitedInput[1];
- int flyLenght = int.Parse(SplitedInput[2]);
- try
- {
- fieldSize[ladyBugIndex] = 0;
- }
- catch (Exception)
- {
- continue;
- }
- int indexNewBug = 0;
- if (directory == "right")
- {
- indexNewBug = ladyBugIndex + flyLenght;
- if (fieldSize.Length > indexNewBug)
- {
- while (fieldSize.Length - 1 >= indexNewBug)
- {
- if (fieldSize[indexNewBug] == 0)
- {
- fieldSize[indexNewBug] = 1;
- break;
- }
- else
- {
- indexNewBug *= 2;
- }
- }
- }
- }
- if (directory == "left")
- {
- indexNewBug = ladyBugIndex - flyLenght;
- int fullSize = fieldSize.Length - 1;
- if (indexNewBug >=0)
- {
- while (indexNewBug >= 0)
- {
- if (fieldSize[indexNewBug] == 0)
- {
- fieldSize[indexNewBug] = 1;
- break;
- }
- else
- {
- indexNewBug -= flyLenght;
- }
- }
- }
- }
- }
- Console.WriteLine(string.Join(" ", fieldSize));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement