Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _10._1Калинки
- {
- class Program
- {
- static void Main(string[] args)
- {
- int arrRange = int.Parse(Console.ReadLine());
- int[] indexesWith_1_OnThem = Console.ReadLine()
- .Split(' ')
- .Select(int.Parse)
- .ToArray();
- int[] resultArr = new int[arrRange];
- for (int i = 0; i < indexesWith_1_OnThem.Length; i++)
- {
- if (indexesWith_1_OnThem[i] > -1 && indexesWith_1_OnThem[i] < resultArr.Length)
- {
- resultArr[indexesWith_1_OnThem[i]] = 1;
- }
- }
- while (true)
- {
- string[] arrCommands = Console.ReadLine()
- .Split()
- .ToArray();
- if (arrCommands[0] == "end")
- {
- Console.WriteLine(string.Join(' ', resultArr));
- return;
- }
- int insectOnIndex = int.Parse(arrCommands[0]);
- int toMoveWith = int.Parse(arrCommands[2]);
- if (insectOnIndex < 0 || insectOnIndex >= arrRange)
- {
- continue;
- }
- if (resultArr[insectOnIndex] == 0) // must be 1
- {
- continue;
- }
- if (toMoveWith < 0 && arrCommands[1] == "left")
- {
- arrCommands[1] = "right";
- toMoveWith = Math.Abs(toMoveWith);
- }
- else if (toMoveWith < 0 && arrCommands[1] == "right")
- {
- arrCommands[1] = "left";
- toMoveWith = Math.Abs(toMoveWith);
- }
- while (true)
- {
- if (arrCommands[1] == "right")
- {
- if (insectOnIndex + toMoveWith >= arrRange || insectOnIndex + toMoveWith < 0) // flies away
- {
- resultArr[insectOnIndex] = 0;
- break;
- }
- if (resultArr[insectOnIndex + toMoveWith] == 1)
- {
- toMoveWith += 1;
- }
- else if (resultArr[insectOnIndex + toMoveWith] == 0)
- {
- resultArr[insectOnIndex + toMoveWith] = 1;
- resultArr[insectOnIndex] = 0;
- break;
- }
- }
- else if (arrCommands[1] == "left")
- {
- if (insectOnIndex - toMoveWith >= arrRange || insectOnIndex - toMoveWith < 0) // flies away
- {
- resultArr[insectOnIndex] = 0;
- break;
- }
- if (resultArr[insectOnIndex - toMoveWith] == 1)
- {
- toMoveWith -= 1;
- }
- else if (resultArr[insectOnIndex - toMoveWith] == 0)
- {
- resultArr[insectOnIndex - toMoveWith] = 1;
- resultArr[insectOnIndex] = 0;
- break;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement