Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _2.Ladybugs
- {
- class Program
- {
- static void Main()
- {
- var fieldSize = int.Parse(Console.ReadLine());
- var ladybugIndexes = Console.ReadLine()
- .Split().Select(int.Parse)
- .Where(a => a >= 0 && a < fieldSize)
- .ToArray();
- var ladybugs = new int[fieldSize];
- for (int i = 0; i < ladybugIndexes.Length; i++)
- {
- var currentLadyBugsIndex = ladybugIndexes[i];
- ladybugs[currentLadyBugsIndex] = 1;
- }
- var line = Console.ReadLine();
- while (line != "and")
- {
- var tokens = line.Split();
- var ladybugsIndex = int.Parse(tokens[0]);
- var direction = (tokens[1]);
- var flyLenght = int.Parse(tokens[2]);
- if (ladybugsIndex < 0 || ladybugsIndex >= ladybugs.Length)
- {
- line = Console.ReadLine();
- continue;
- }
- if (ladybugs[ladybugsIndex] ==0)
- {
- line = Console.ReadLine();
- continue;
- }
- MoveLadybug (ladybugs, ladybugsIndex, flyLenght, direction);
- line = Console.ReadLine();
- }
- Console.WriteLine(string.Join(" ", ladybugs));
- }
- static void MoveLadybug(int[] ladybugs, int ladybugsIndex, int flyLenght, string direction)
- {
- ladybugs[ladybugsIndex] = 0;
- var leftArrayOrFoundPlase = false;
- while (!leftArrayOrFoundPlase)
- {
- switch (direction)
- {
- case "left":
- ladybugsIndex -= flyLenght;
- break;
- case "right":
- ladybugsIndex += flyLenght;
- break;
- }
- if (ladybugsIndex < 0 || ladybugsIndex >= ladybugs.Length)
- {
- leftArrayOrFoundPlase = true;
- continue;
- }
- if (ladybugs[ladybugsIndex]==1)
- {
- continue;
- }
- if (ladybugs[ladybugsIndex]==0)
- {
- ladybugs[ladybugsIndex] = 1;
- leftArrayOrFoundPlase = true;
- continue;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment