Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace CheatSheet
- {
- class Program
- {
- public static void Main(string[] args)
- {
- int size = int.Parse(Console.ReadLine());
- int[] ladyBugs = new int[size];
- int[] placesOfLadyBugs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int ladyBugPlaceHolder = 0;
- for (int currentElement = 0; currentElement < placesOfLadyBugs.Length; currentElement++)
- {
- ladyBugPlaceHolder = placesOfLadyBugs[currentElement];
- ladyBugs[ladyBugPlaceHolder] = 1;
- }
- while (true)
- {
- string[] command = Console.ReadLine().Split(' ').ToArray();
- if (command[0] != "end")
- {
- int curretPosition = int.Parse(command[0]);
- string direction = command[1];
- int cellsToMove = int.Parse(command[2]);
- int finalCellForABug = (curretPosition + cellsToMove);
- bool movementFinished = false;
- if (direction == "right")
- {
- while (!movementFinished)
- {
- if (ladyBugs[curretPosition] == 0)
- {
- movementFinished = true;
- }
- else if (ladyBugs[curretPosition] != 0)
- {
- if (finalCellForABug >= ladyBugs.Length)
- {
- ladyBugs[curretPosition] = 0;
- movementFinished = true;
- }
- else
- {
- ladyBugs[curretPosition] = 0;
- ladyBugs[finalCellForABug] = 1;
- movementFinished = true;
- }
- }
- }
- }
- }
- else
- {
- break;
- }
- }
- Console.WriteLine(string.Join(" ", ladyBugs));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment