Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace retake
- {
- class Program
- {
- static void Main(string[] args)
- {
- int sizeArr = int.Parse(Console.ReadLine());
- int[] arr = new int[sizeArr];
- int[] leidyBIndex = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- for (int i = 0; i < leidyBIndex.Length; i++)
- {
- for (int j = 0; j < arr.Length; j++)
- {
- if (leidyBIndex[i] == j)
- {
- arr[j] = 1;
- break;
- }
- }
- }
- string command = Console.ReadLine();
- while (command != "end")
- {
- string[] commandArr = command.Split();
- int fromIndex = int.Parse(commandArr[0]);
- int toIndex = int.Parse(commandArr[2]);
- if (fromIndex >= 0 && fromIndex < arr.Length && arr[fromIndex] == 1)
- {
- arr[fromIndex] = 0;
- string direction = commandArr[1];
- if (direction == "right")
- {
- int stop = fromIndex + toIndex;
- if (stop < arr.Length && stop >= 0)
- {
- if (arr[stop] == 0)
- {
- arr[stop] = 1;
- }
- else
- {
- for (int j = stop + 1; j < arr.Length; j++)
- {
- if (arr[j] == 0)
- {
- arr[j] = 1;
- break;
- }
- }
- }
- }
- }
- else if (direction == "left")
- {
- int stop = fromIndex - toIndex;
- if (stop < arr.Length && stop >= 0)
- {
- if (arr[stop] == 0)
- {
- arr[stop] = 1;
- }
- else if (arr[stop] == 1)
- {
- for (int j = stop + 1; j < arr.Length; j++)
- {
- if (arr[j] == 0)
- {
- arr[j] = 1;
- break;
- }
- }
- }
- }
- }
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(string.Join(" ", arr));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement