Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Reflection.Metadata;
- using System.Text;
- using System.Threading.Tasks;
- class LadyBugs
- {
- static void decodingComand(string line, ref long startIndex, ref long flyIndex, ref bool isRight)
- {
- string [] comand = line.Split(' ');
- startIndex = int.Parse(comand[0]);
- flyIndex = int.Parse(comand[2]);
- if(comand[1] == "right")
- isRight = true;
- else
- isRight = false;
- }
- static void move(long startIndex, long flyIndex, ref int[] field, bool isRight)
- {
- if(field[startIndex] == 1)
- {
- if(!isRight)
- flyIndex *= -1;
- long newPosition;
- newPosition = startIndex + flyIndex;
- //Out of range
- if(newPosition > (field.Length - 1) || newPosition < 0)
- {
- field[startIndex] = 0;
- return;
- }
- while(true)
- {
- if(field[newPosition] == 0)
- {
- field[startIndex] = 0;
- field[newPosition] = 1;
- return;
- }
- newPosition += flyIndex;
- if(newPosition > (field.Length - 1) || newPosition < 0)
- {
- field[startIndex] = 0;
- return;
- }
- }
- }
- }
- static void Main()
- {
- long size = long.Parse(Console.ReadLine());
- string [] cordString = Console.ReadLine().Split(' ');
- int [] field = new int[size];
- long pos;
- foreach(string elem in cordString)
- {
- pos = long.Parse(elem);
- field[pos] = 1;
- }
- long start = 0, fly = 0;
- bool isRight = false;
- string line = Console.ReadLine();
- while(line != "end")
- {
- decodingComand(line, ref start, ref fly, ref isRight);
- move(start, fly, ref field, isRight);
- line = Console.ReadLine();
- }
- Console.WriteLine(String.Join(" ", field));
- }
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment