-4
我需要帮助找到我通过Thor挑战Codeingame上的x和y值的差异替代方法所犯的错误。为什么这个代码只输出“”? (Codeingame的Thor挑战)
这里是游戏圈的代码:
// game loop
while (1) {
int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
cin >> remainingTurns; cin.ignore();
int difx = lightX-initialTX;
int dify = lightY-initialTY;
float mathquot=dify/difx;
string out ="";
if(difx==0 || dify==0){
if(difx=0){
if(dify<0) out="W"; initialTY-=1;
if(dify>0) out="E"; initialTY+=1;
}
if(dify=0){
if(difx<0) out="N"; initialTX-=1;
if(difx>0) out="S"; initialTX+=1;
}
}else{
if(mathquot>0 && (difx>0 && dify>0)) out="SE"; initialTY +=1; initialTX+=1;
if(mathquot>0 && (difx<0 && dify<0)) out="NW"; initialTY -=1; initialTX-=1;
if(mathquot<0 && difx<0) out="SW"; initialTY +=1; initialTX-=1;
if(mathquot<0 && dify<0) out="NE"; initialTY -=1; initialTX+=1;
}
// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
// A single line providing the move to be made: N NE E SE S SW W or NW
cout << out << endl;
}
欢迎来到Stack Overflow!这听起来像你可能需要学习如何使用调试器来遍历代码。使用一个好的调试器,您可以逐行执行您的程序,并查看它与您期望的偏离的位置。如果你打算做任何编程,这是一个重要的工具。进一步阅读:** [如何调试小程序](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)** – NathanOliver