Advertisement
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 _10_LadyBugs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int fieldLenght = int.Parse(Console.ReadLine());
- int[] field = new int[fieldLenght];
- int[] bugsIndexes = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- for (int i = 0; i < bugsIndexes.Length; i++)
- {
- if (bugsIndexes[i] > field.Length - 1 || bugsIndexes[i] < 0)
- {
- continue;
- }
- else
- {
- field[bugsIndexes[i]] = 1;
- }
- }
- string command = string.Empty;
- while (true)
- {
- command = Console.ReadLine();
- if (command == "end")
- {
- break;
- }
- string[] flyLenght = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- int index = int.Parse(flyLenght[0]);
- int moveLenght = int.Parse(flyLenght[2]);
- string direction = flyLenght[1];
- int moveLenghtOriginal = moveLenght;
- if (index >= 0 && index < field.Length)
- {
- if (direction == "right" && field[index] == 1 && moveLenght > 0)
- {
- if (index == field.Length - 1)
- {
- field[index] = 0;
- continue;
- }
- else
- {
- field[index] = 0;
- for (int i = index + 1; i < field.Length; i++)
- {
- if (field[i] == 1)
- {
- moveLenght = moveLenghtOriginal;
- }
- else if (field[i] != 1)
- {
- moveLenght--;
- }
- if (moveLenght == 0)
- {
- field[i] = 1;
- }
- }
- }
- }
- else if (direction == "right" && field[index] == 1 && moveLenght < 0)
- {
- if (index == 0)
- {
- field[index] = 0;
- continue;
- }
- else
- {
- field[index] = 0;
- for (int i = index - 1; i >= 0; i--)
- {
- if (field[i] == 1)
- {
- moveLenght = moveLenghtOriginal;
- }
- else if (field[i] != 1)
- {
- moveLenght++;
- }
- if (moveLenght == 0)
- {
- field[i] = 1;
- }
- }
- }
- }
- else if (direction == "left" && field[index] == 1 && moveLenght > 0)
- {
- if (index == 0)
- {
- field[index] = 0;
- continue;
- }
- else
- {
- field[index] = 0;
- for (int i = index - 1; i >= 0; i--)
- {
- if (field[i] == 1)
- {
- moveLenght = moveLenghtOriginal;
- }
- else if (field[i] != 1)
- {
- moveLenght--;
- }
- if (moveLenght == 0)
- {
- field[i] = 1;
- }
- }
- }
- }
- else if (direction == "left" && field[index] == 1 && moveLenght < 0)
- {
- if (index == field.Length - 1)
- {
- field[index] = 0;
- continue;
- }
- else
- {
- field[index] = 0;
- for (int i = index + 1; i < field.Length; i++)
- {
- if (field[i] == 1)
- {
- moveLenght = moveLenghtOriginal;
- }
- else if (field[i] != 1)
- {
- moveLenght++;
- }
- if (moveLenght == 0)
- {
- field[i] = 1;
- }
- }
- }
- }
- }
- }
- Console.WriteLine(string.Join(" ", field));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement