Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public class Program
- {
- public static void Main()
- {
- int fieldSize = int.Parse(Console.ReadLine());
- int [] field = new int [fieldSize];
- int [] initialIndexes = Console.ReadLine().Split().Select(int.Parse).ToArray();
- for (int i=0; i<initialIndexes.Length; i++)
- {
- if (initialIndexes[i]>=0 && initialIndexes[i]<field.Length)
- {
- field[initialIndexes[i]] =1;
- }
- }
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end")
- {
- break;
- }
- string[] command = input.Split();
- int ladybugIndex = int.Parse(command[0]);
- bool isFirst = true;
- while (ladybugIndex>=0 && ladybugIndex<field.Length && field[ladybugIndex]!=0)
- {
- if (isFirst)
- {
- field[ladybugIndex]=0;
- isFirst = false;
- }
- string direction = command[1];
- int flyLength = int.Parse(command[2]);
- if (direction == "left")
- {
- ladybugIndex -= flyLength;
- if (ladybugIndex<field.Length && ladybugIndex>=0)
- {
- if (field[ladybugIndex]!=1)
- {
- field[ladybugIndex]=1;
- break;
- }
- }
- }
- else
- {
- ladybugIndex += flyLength;
- if (ladybugIndex<field.Length && ladybugIndex>=0)
- {
- if (field[ladybugIndex]!=1)
- {
- field[ladybugIndex]=1;
- break;
- }
- }
- }
- }
- }
- Console.WriteLine(string.Join(" ",field));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement