Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Threading.Tasks.Sources;
- namespace Ladybugs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int fieldSize = int.Parse(Console.ReadLine());
- int[] bugsIndexes = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int[] field = new int[fieldSize];
- if (fieldSize == 0)
- {
- return;
- }
- for (int i = 0; i < bugsIndexes.Length; i++)
- {
- int currentIndex = bugsIndexes[i];
- if (0 <= currentIndex && currentIndex < field.Length)
- {
- field[currentIndex] = 1;
- }
- }
- while (true)
- {
- string[] input = Console.ReadLine().Split().ToArray();
- if (input[0] == "end")
- {
- break;
- }
- int startIndex = int.Parse(input[0]);
- string direction = input[1];
- int flyLength = int.Parse(input[2]);
- int currentIndex = startIndex;
- if (0 <= startIndex && startIndex < field.Length)
- {
- if (flyLength < 0)
- {
- flyLength = Math.Abs(flyLength);
- if (direction == "left")
- {
- direction = "right";
- }
- else
- {
- direction = "left";
- }
- }
- while (true)
- {
- if (direction == "right")
- {
- int indexAfterFly = currentIndex + flyLength;
- if (indexAfterFly >= field.Length)
- {
- field[startIndex] = 0;
- break;
- }
- if (field[indexAfterFly] == 0)
- {
- field[indexAfterFly] = 1;
- field[startIndex] = 0;
- break;
- }
- else
- {
- currentIndex = indexAfterFly;
- }
- }
- else
- {
- int indexAfterFly = currentIndex - flyLength;
- if (indexAfterFly < 0)
- {
- field[startIndex] = 0;
- break;
- }
- if (field[indexAfterFly] == 0)
- {
- field[indexAfterFly] = 1;
- field[startIndex] = 0;
- break;
- }
- else
- {
- currentIndex = indexAfterFly;
- }
- }
- }
- }
- }
- Console.WriteLine(String.Join(" ", field));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement