Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- 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++)
- {
- int currIndex = initialIndexes[i];
- if (currIndex>=0 && currIndex<=field.Length-1)
- {
- field[currIndex]= 1;
- }
- }
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "end")
- {
- break;
- }
- string[]tokens = command.Split();
- int ladybugIndex = int.Parse(tokens[0]);
- bool isFirst = true;
- while((ladybugIndex>=0 && ladybugIndex<=field.Length-1) && field[ladybugIndex]!=0)
- {
- if (isFirst)
- {
- field[ladybugIndex]=0;
- isFirst = false;
- }
- string direction = tokens[1];
- int flyLen = int.Parse(tokens[2]);
- if (direction == "right")
- {
- ladybugIndex += flyLen;
- }
- else
- {
- ladybugIndex -= flyLen;
- }
- if (ladybugIndex>=0 && ladybugIndex<=field.Length-1)
- {
- if (field[ladybugIndex]==0)
- {
- field[ladybugIndex]=1;
- break;
- }
- }
- }
- }
- Console.WriteLine(string.Join(" ",field));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement