Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace LadyBugs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int fieldSize = int.Parse(Console.ReadLine());
- int[] bugsInFieldstr = Console.ReadLine()
- .Split(" ")
- .Select(int.Parse)
- .ToArray();
- int[] BugsField = new int[fieldSize];
- for (int i = 0; i < bugsInFieldstr.Length; i++)
- {
- if (bugsInFieldstr[i] < fieldSize && bugsInFieldstr[i] >= 0)
- {
- BugsField[bugsInFieldstr[i]] = 1;
- }
- }
- string moveBugsCom = Console.ReadLine();
- while (moveBugsCom != "end")
- {
- string[] moveBugsCommand = moveBugsCom
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .ToArray(); ;
- int indexIsFreeCheck = int.Parse(moveBugsCommand[0]);
- int flyTimes = int.Parse(moveBugsCommand[2]);
- if (indexIsFreeCheck >= BugsField.Length
- || indexIsFreeCheck < 0
- || flyTimes <= 0
- || BugsField[indexIsFreeCheck] != 1)
- {
- //do nothing :)
- }
- else if (moveBugsCommand[1] == "right")
- {
- if (flyTimes < 0)
- {
- MoveLeft(moveBugsCommand, BugsField);
- }
- else
- {
- MoveRight(moveBugsCommand, BugsField);
- }
- }
- else if (moveBugsCommand[2] == "left")
- {
- if (flyTimes < 0)
- {
- MoveRight(moveBugsCommand, BugsField);
- }
- else
- {
- MoveLeft(moveBugsCommand, BugsField);
- }
- }
- moveBugsCom = Console.ReadLine();
- }
- Console.WriteLine(string.Join(" ", BugsField));
- }
- static void MoveRight(string[] moveBugsCommand, int[] BugsField)
- {
- int startBugIndex = int.Parse(moveBugsCommand[0]);
- int flyTimes = int.Parse(moveBugsCommand[2]);
- for (int i = startBugIndex; i < BugsField.Length; i += flyTimes)
- {
- if (i + flyTimes >= BugsField.Length)
- {
- BugsField[startBugIndex] = 0;
- break;
- }
- else if (BugsField[i + flyTimes] == 0 && i + flyTimes < BugsField.Length)
- {
- BugsField[startBugIndex] = 0;
- BugsField[i + flyTimes] = 1;
- break;
- }
- }
- }
- static void MoveLeft(string[] moveBugsCommand, int[] BugsField)
- {
- int startBugIndex = int.Parse(moveBugsCommand[0]);
- int flyTimes = int.Parse(moveBugsCommand[2]);
- for (int i = startBugIndex; i < BugsField.Length; i -= flyTimes)
- {
- if (i - flyTimes < 0)
- {
- BugsField[startBugIndex] = 0;
- break;
- }
- else if (BugsField[i - flyTimes] == 0 && i - flyTimes >= 0)
- {
- BugsField[startBugIndex] = 0;
- BugsField[i - flyTimes] = 1;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement