+ 1
2d map code coach case4 test faild
I need help please I made the code as you see to found the first "P",the x represent to the row and the y represent to the column could any body tell me why case 4 always faild https://sololearn.com/compiler-playground/cvUpQaUkgF5S/?ref=app
2 Respuestas
+ 5
ELBARAA Gamal Galal ,
the code is nearly perfect, except the line:
...
Console.Write((yb-ya)+(xb-xa));
...
in some cases during the calculation of this line (depending on the test cases used), results can get *negative values* which causes incorrect results.
we can avoid this by using Math.Abs(...) around of each of both expressions.
+ 1
ELBARAA Gamal Galal
Lothar is right, use Math.Abs()
Console.Write(Math.Abs(yb-ya)+Math.Abs(xb-xa));
also, maybe this is a shorter way to do it:
https://sololearn.com/compiler-playground/cZg7FxaHsZYX/?ref=app