Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Exercise2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] field = new int[int.Parse(Console.ReadLine())];
- int[] bugs = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- for (int i = 0; i < bugs.Length; i++)
- {
- if (bugs[i] >= 0 && bugs[i] < field.Length)
- {
- field[bugs[i]] = 1;
- }
- }
- while (true)
- {
- string[] input = Console.ReadLine().Split(new char[] {' '},StringSplitOptions.RemoveEmptyEntries);
- if (input[0] == "end")
- {
- break;
- }
- int currentIndex = int.Parse(input[0]);
- string direction = input[1];
- int flyLength = int.Parse(input[2]);
- if (currentIndex < 0 || currentIndex > (field.Length - 1))
- {
- continue;
- }
- if (field[currentIndex] == 0)
- {
- continue;
- }
- field[currentIndex] = 0;
- while (true)
- {
- if (direction == "right")
- {
- if (currentIndex + flyLength > field.Length - 1)
- {
- break;
- }
- else if (field[currentIndex + flyLength] == 1)
- {
- flyLength = flyLength * 2;
- }
- else
- {
- field[currentIndex + flyLength] = 1;
- break;
- }
- }
- if (direction == "left")
- {
- if (currentIndex - flyLength < 0)
- {
- break;
- }
- else if (field[currentIndex - flyLength] == 1)
- {
- flyLength = flyLength * 2;
- }
- else
- {
- field[currentIndex - flyLength] = 1;
- break;
- }
- }
- }
- }
- Console.WriteLine(string.Join(" ", field));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement