I was solving a problem in CodeinGame where i have to take Thor to the light lightx & lightY is the light position & thorx & thory is the position of thor.& initiaTX , initiaTX are starting thor position but it fails some test cases on the site for eg : if initial pos is (5,4) it passes Log but if initial pos is (31,17) it fails Log
My code
string[] inputs = Console.ReadLine().Split(' ');
int lightX = int.Parse(inputs[0]); // the X position of the light of power
int lightY = int.Parse(inputs[1]); // the Y position of the light of power
int initialTX = int.Parse(inputs[2]); // Thor's starting X position
int initialTY = int.Parse(inputs[3]); // Thor's starting Y position
// game loop
int thorx=initialTX;
int thory=initialTY;
string directionX, directionY;
while (true)
{
int remainingTurns = int.Parse(Console.ReadLine()); // The remaining amount of turns Thor can move. Do not remove this line.
// Write an action using Console.WriteLine()
// To debug: Console.Error.WriteLine("Debug messages...");
if (thorx>lightX)
{
directionX="W";
thorx=-1;
Console.WriteLine("W");
}
else if (thorx<lightX)
{
directionX="E";
thorx=+1;
Console.WriteLine("E");
}
else
{
if (thory>lightY)
{
directionY="N";
thory=-1;
Console.WriteLine("N");
}
else if (thory<lightY)
{
directionY="S";
thorx=+1;
Console.WriteLine("S");
}
}
CodeinGame Link it's the 2nd problem Power of Thor
Aucun commentaire:
Enregistrer un commentaire