Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Ladybugs_second_try
- {
- class Program
- {
- static string MoveDir(string moveDirection, int lengthMove)
- {
- if (moveDirection == "right" && lengthMove < 0)
- moveDirection = "left";
- else if (moveDirection == "left" && lengthMove < 0)
- moveDirection = "right";
- return moveDirection;
- }
- static void Main()
- {
- int fieldSize = int.Parse(Console.ReadLine());
- //create the field
- int[] field = new int[fieldSize];
- //enter the initial positions
- int[] initialPos = Console.ReadLine().Split().Select(int.Parse).ToArray();
- //put the bugs in place
- for (int i = 0; i < initialPos.Length; i++)
- {
- if (initialPos[i] >= 0 && initialPos[i] < field.Length)
- {
- field[initialPos[i]] = 1;
- }
- }
- //first command
- string commandMove = Console.ReadLine();
- //set the process for commands
- while (commandMove != "end")
- {
- string[] directions = commandMove.Split();
- int currPos = int.Parse(directions[0]);
- string moveDirection = directions[1];
- int lenghtMove = int.Parse(directions[2]);
- /*if (lenghtMove == 0)
- {
- break;
- }*/
- if (currPos >= 0 && currPos < field.Length && field[currPos] != 0)
- {
- int newPos = currPos;
- moveDirection = MoveDir(moveDirection, lenghtMove);
- lenghtMove = Math.Abs(lenghtMove);
- if (moveDirection == "right")
- {
- while (newPos < field.Length && field[newPos] == 1)
- {
- if (lenghtMove == 0)
- {
- break;
- }
- newPos += lenghtMove;
- }
- }
- else if (moveDirection == "left")
- {
- while (newPos >= 0 && field[newPos] == 1)
- {
- if (lenghtMove == 0)
- {
- break;
- }
- newPos -= lenghtMove;
- }
- }
- if (newPos >= 0 && newPos < field.Length)
- {
- field[newPos] = 1;
- }
- if (lenghtMove != 0)
- {
- field[currPos] = 0;
- }
- }
- commandMove = Console.ReadLine();
- }
- Console.WriteLine(string.Join(' ', field));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement