Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ladybugs
- {
- class Program
- {
- static void Main()
- {
- int sizeField = int.Parse(Console.ReadLine());
- if (sizeField <= 0)
- {
- return;
- }
- long[] indexOfLadybug = Console.ReadLine()
- .Trim()
- .Split()
- .Select(long.Parse)
- .ToArray();
- long[] field = new long[sizeField];
- for (int i = 0; i < indexOfLadybug.Length; i++)
- {
- if (!(indexOfLadybug[i] < 0) && !(indexOfLadybug[i] >= field.Length))
- {
- field[indexOfLadybug[i]] = 1;
- }
- }
- string command = Console.ReadLine();
- if (String.IsNullOrEmpty(command))
- {
- Console.WriteLine(string.Join(" ",field));
- return;
- }
- string[] commandStr = command
- .Trim()
- .Split();
- bool checkEmpty = true;
- long endFly = 0;
- while (!commandStr[0].Equals("end"))
- {
- long indexLady = long.Parse(commandStr[0]);
- string direction = commandStr[1];
- long lengthFly = long.Parse(commandStr[2]);
- switch (direction)
- {
- case "right":
- if (indexLady >= 0 && indexLady < field.Length && field[indexLady]==1)
- {
- endFly = indexLady + lengthFly;
- checkEmpty = true;
- if (lengthFly >= 0 && endFly < field.Length)
- {
- do
- {
- if (field[endFly] != 1)
- {
- field[endFly] = 1;
- field[indexLady] = 0;
- checkEmpty = false;
- }
- else
- {
- endFly+=lengthFly;
- if (endFly >= field.Length)
- {
- field[indexLady] = 0;
- break;
- }
- }
- } while (checkEmpty);
- checkEmpty = true;
- }
- else if (lengthFly >= 0 && endFly >= field.Length)
- {
- field[indexLady] = 0;
- }
- else if (lengthFly < 0 && endFly >= 0)
- {
- do
- {
- if (field[endFly] != 1)
- {
- field[endFly] = 1;
- field[indexLady] = 0;
- checkEmpty = false;
- }
- else
- {
- endFly-=lengthFly;
- if (endFly < 0)
- {
- field[indexLady] = 0;
- break;
- }
- }
- } while (checkEmpty);
- checkEmpty = true;
- }
- else if (lengthFly < 0 && endFly < 0 )
- {
- field[indexLady] = 0;
- }
- }
- break;
- case "left":
- if (indexLady >= 0 && indexLady < field.Length && field[indexLady]==1)
- {
- endFly = indexLady - lengthFly;
- if (lengthFly >= 0 && endFly >= 0)
- {
- checkEmpty = true;
- do
- {
- if (field[endFly] != 1)
- {
- field[endFly] = 1;
- field[indexLady] = 0;
- checkEmpty = false;
- }
- else
- {
- endFly-=lengthFly;
- if (endFly < 0)
- {
- field[indexLady] = 0;
- break;
- }
- }
- } while (checkEmpty);
- checkEmpty = true;
- }
- else if (lengthFly >= 0 && endFly < 0)
- {
- field[indexLady] = 0;
- }
- else if (lengthFly < 0 && endFly < field.Length)
- {
- checkEmpty = true;
- do
- {
- if (field[endFly] != 1)
- {
- field[endFly] = 1;
- field[indexLady] = 0;
- checkEmpty = false;
- }
- else
- {
- endFly+=lengthFly;
- if (endFly >= field.Length)
- {
- field[indexLady] = 0;
- break;
- }
- }
- } while (checkEmpty);
- checkEmpty = true;
- }
- else if (lengthFly < 0 && endFly >= field.Length)
- {
- field[indexLady] = 0;
- }
- }
- break;
- default:
- break;
- }
- commandStr = Console.ReadLine()
- .Trim()
- .Split();
- }
- Console.WriteLine(string.Join(" ",field));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement