Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02._Ladybugs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int fieldSize = int.Parse(Console.ReadLine());
- string unseparatedIndexes = Console.ReadLine();
- int[] ladybugIndexes = unseparatedIndexes
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- var lady = new int[fieldSize];
- for (int i = 0; i < ladybugIndexes.Length; i++)
- {
- lady[ladybugIndexes[i]] = 1;
- }
- string moves = Console.ReadLine();
- while (moves != "end")
- {
- string[] splitedInput = moves.Split().ToArray();
- long ladybugIndex = long.Parse(splitedInput[0]);
- string direction = splitedInput[1];
- long flyLength = long.Parse(splitedInput[2]);
- if (direction == "right")
- {
- while (true)
- {
- lady[ladybugIndex] = 0;
- if (ladybugIndex + flyLength + 1 > lady.Length)
- {
- break;
- }
- else if(lady[ladybugIndex + flyLength] == 0)
- {
- lady[ladybugIndex + flyLength] = 1;
- break;
- }
- else
- {
- for (long i = ladybugIndex; i < lady.Length - 1; i++)
- {
- if (lady[i + 1] == 0)
- {
- lady[i + 1] = 1;
- break;
- }
- }
- }
- break;
- }
- }
- else
- {
- while (true)
- {
- lady[ladybugIndex] = 0;
- if (ladybugIndex - flyLength - 1 > lady.Length)
- {
- break;
- }
- else if (lady[ladybugIndex - flyLength] == 0)
- {
- lady[ladybugIndex - flyLength] = 1;
- break;
- }
- else
- {
- for (long i = ladybugIndex; i < lady.Length - 1; i--)
- {
- if (lady[i - 1] == 0)
- {
- lady[i - 1] = 1;
- break;
- }
- }
- }
- break;
- }
- }
- moves = Console.ReadLine();
- }
- Console.WriteLine(string.Join(" ", lady));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement