LadyBugs 30/100
Здравейте,
Ако може някой по разбиращ да хвърли един поглед на кода ми, че не успявам да си намеря грешката , с примерните входове си работи добре но джъдж ми дава 30 от 100.
Условие(задача 10): https://softuni.bg/trainings/resources/officedocument/43069/exercise-problem-descriptions-csharp-fundamentals-september-2019/2438
Това е кода ми:
using System;
using System.Linq;
namespace _10._LadyBugs
{
class Program
{
static void Main(string[] args)
{
int fieldSize = int.Parse(Console.ReadLine());
int[] ladyBugsAtIndexes = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] field = new int[fieldSize];
// inserting ladybugs at given indexes
for (int i = 0; i < ladyBugsAtIndexes.Length; i++)
{
int elementToInsertAtIndex = ladyBugsAtIndexes[i];
if (elementToInsertAtIndex > field.Length - 1)
{
continue;
}
field[elementToInsertAtIndex] = 1;
}
string command;
// executing commands
while ((command = Console.ReadLine()) != "end")
{
//{ladybug index} {direction} {fly length}
string[] instructions = command.Split();
int index = int.Parse(instructions[0]);
int flyLength = int.Parse(instructions[2]);
string direction = instructions[1];
if (field[index] == 0)
{
continue;
}
if (index > field.Length - 1 || index < 0)
{
continue;
}
if (flyLength == 0)
{
continue;
}
if (flyLength < 0)
{
flyLength = Math.Abs(flyLength);
if (direction == "left")
{
direction = "right";
}
else
{
direction = "left";
}
}
if((index + flyLength > field.Length - 1) && (direction == "right"))
{
if(field[index] <= field.Length - 1)
{
field[index] = 0;
}
continue;
}
if((index - flyLength < 0) && (direction == "left"))
{
if(field[index] >= 0)
{
field[index] = 0;
}
continue;
}
// moving the ladybug to right
if (direction == "right")
{
if (index + flyLength > field.Length - 1)
{
field[index] = 0;
continue;
}
else
{
if (field[index + flyLength] == 0)
{
field[index + flyLength] = 1;
field[index] = 0;
continue;
}
for (int i = index + flyLength; i < field.Length; i += flyLength)
{
if (field[i] == 1)
{
continue;
}
else
{
field[i] = 1;
field[index] = 0;
break;
}
}
field[index] = 0;
}
}
// moving the ladybug to left
else
{
if (index - flyLength < 0)
{
field[index] = 0;
continue;
}
else
{
if (field[index - flyLength] == 0)
{
field[index - flyLength] = 1;
field[index] = 0;
continue;
}
for (int i = index - flyLength; i >= 0; i -= flyLength)
{
if (field[i] == 1)
{
continue;
}
else
{
field[i] = 1;
field[index] = 0;
break;
}
}
field[index] = 0;
}
}
}
Console.WriteLine(string.Join(" ", field));
}
}
}