Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Linq;
- using System.Numerics;
- namespace SoftuniExercisesWithVariables
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter the size of the field: ");
- int fieldSize = int.Parse(Console.ReadLine());
- int[] field = new int[fieldSize];
- Console.WriteLine("Enter the indexes of the ladybugs: ");
- int[] initialIndexes = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
- for(int i = 0; i < initialIndexes.Length; i++)
- {
- //setting ladybugs inside the field
- field[initialIndexes[i]] = 1;
- }
- string input = "";
- while((input = Console.ReadLine()) != "end")
- {
- string[] array = input.Split(" ");
- int index = int.Parse(array[0]);
- string direction = array[1];
- int moves = int.Parse(array[2]);
- if(direction == "left" && moves < 0)
- {
- moves = -moves;
- }
- else if(direction == "left" && moves > 0)
- {
- moves = -moves;
- }
- if(index<0 || index >= fieldSize)
- {
- continue;
- }
- else if(fieldSize <= index + moves || index + moves < 0)
- {
- field[index] = 0;
- }
- else
- {
- if(field[index+moves] == 0)
- {
- field[index + moves] = 1;
- field[index] = 0;
- }
- else
- {
- field[index] = 0;
- while (field[index + moves] != 0)
- {
- moves++;
- if(field[index+moves] == 0)
- {
- field[index + moves] = 1;
- break;
- }
- }
- }
- }
- }
- for(int k = 0; k < fieldSize; k++)
- {
- Console.Write(field[k] + " ");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment