Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02Problem_Ladybugs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int fieldSize = int.Parse(Console.ReadLine());
- long[] flyField = new long[fieldSize];
- string flyCommand = string.Empty;
- long[] buggedIndexes = Console.ReadLine().Split().Select(long.Parse).ToArray();
- foreach (var buggedIndex in buggedIndexes)
- {
- if (buggedIndex >= 0 && buggedIndex <= flyField.Length - 1)
- {
- flyField[buggedIndex] = 1;
- }
- }
- while ((flyCommand = Console.ReadLine()) != "end")
- {
- string[] tokens = flyCommand.Split().Select(x => x.Trim()).ToArray();
- long startIndex = long.Parse(tokens[0]);
- long flyLength = long.Parse(tokens[2]);
- bool isOutside = startIndex < 0 || startIndex > flyField.Length - 1;
- if (isOutside || flyLength == 0)
- {
- continue;
- }
- string direction = tokens[1];
- long landed = startIndex;
- while (flyField[startIndex] == 1)
- {
- switch (direction)
- {
- case "right":
- landed += flyLength;
- break;
- case "left":
- landed -= flyLength;
- break;
- }
- if (landed > flyField.Length - 1 || landed < 0)
- {
- flyField[startIndex] = 0;
- break;
- }
- if (flyField[landed] == 1)
- {
- continue;
- }
- flyField[startIndex] = 0;
- flyField[landed] = 1;
- break;
- }
- }
- Console.WriteLine(string.Join(" ", flyField));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement