Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LadyBugs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] fieldSize = new int[int.Parse(Console.ReadLine())];
- int[] ladyBugsIndexes = Console.ReadLine().Split().Select(int.Parse).ToArray();
- List<string> commands = Console.ReadLine().Split().ToList();
- for (int i = 0; i < ladyBugsIndexes.Length; i++)
- {
- fieldSize[ladyBugsIndexes[i]] = 1;
- }
- while (commands[0] != "end")
- {
- int startIndex = int.Parse(commands[0]);
- int flyLength = int.Parse(commands[2]);
- int endIndex = 0;
- if (startIndex <= fieldSize.Length-1 && fieldSize[startIndex]==1) //we have a ladybug found in the field
- {
- if (commands[1]=="right")
- {
- endIndex = startIndex + flyLength;
- }
- else if (commands[1]=="left")
- {
- endIndex = startIndex - flyLength;
- }
- if (endIndex <= fieldSize.Length-1 && endIndex >=0 && fieldSize[endIndex] !=1)
- {
- fieldSize[endIndex] = 1;
- }
- else
- {
- try
- {
- while (endIndex <= fieldSize.Length - 1 && endIndex >= 0 && fieldSize[endIndex] != 0)
- {
- endIndex += flyLength;
- }
- fieldSize[endIndex] = 1;
- }
- catch (Exception)
- {
- fieldSize[startIndex] = 0;
- commands = Console.ReadLine().Split(" ").ToList();
- continue;
- }
- }
- fieldSize[startIndex] = 0;
- }
- else
- {
- continue;
- }
- commands = Console.ReadLine().Split(" ").ToList();
- }
- Console.WriteLine(string.Join(" ", fieldSize));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement