Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class Ladybugs
- {
- static void Main(string[] args)
- {
- int fieldSize = int.Parse(Console.ReadLine());
- int[] field = new int[fieldSize];
- Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .Where(i => i >= 0 && i < fieldSize)
- .ToList()
- .ForEach(i => field[i] = 1);
- string command = Console.ReadLine();
- while (command != "end")
- {
- string[] tokens = command
- .Split()
- .ToArray();
- int ladybugIndex = int.Parse(tokens[0]);
- string direction = tokens[1];
- int flyLength = int.Parse(tokens[2]);
- int landIndex = ladybugIndex;
- if (direction == "left")
- {
- flyLength *= -1;
- }
- if (ladybugIndex < 0 || ladybugIndex >= fieldSize || field[ladybugIndex] == 0)
- {
- continue;
- }
- field[ladybugIndex] = 0;
- while (true)
- {
- landIndex += flyLength;
- if (landIndex < 0 || landIndex >= fieldSize)
- {
- break;
- }
- if (field[landIndex] == 0)
- {
- field[landIndex] = 1;
- break;
- }
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(string.Join(" ", field));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement