I am currently working on a simple breadth first search that counts the shortest # of steps from point A to point B. My program outputs 14, which is the correct answer, but when I set the
#define DEBUG = true
to
#define DEBUG = false
or if I delete the line
if (DEBUG) cout << '[' << map[i] << ']' << endl;
the # of steps changes from 14 to 16. I am completely baffled as to why this is, especially since the debugging only outputs text. This doesn't make sense to me because the line I'm removing is purely output only!
I've tried moving the line around to different spots, and turning the debugging mode to false while keeping the the line of output still. No luck with that. I have no clue as to why this is affecting my program like this.
Here is some code:
pair<unsigned, unsigned> start;
for (unsigned i = 0; i < n; i++) {
for (unsigned j = 0; j < n; j++) {
if (map[i][j] == 'k') { start = pair<unsigned, unsigned>({i,j}); }
}
if (DEBUG) cout << '[' << map[i] << ']' << endl; //this is the only line I change and then the program breaks
}
//algorithm to count the # of steps
//This part works, but as soon as modify the lines mentioned above
//the program outputs the wrong # of steps
if(reached_end)
cout << move_count << endl;
else
cout << "Impossible" << endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire