Updated with simpler test code …
It would be most helpful to have a #defined flag that would indicate to the code being run whether the program is being run for testing (in the IDE) or for a real Online Judge run (via SUBMIT). I looked it up and found this CodeChef article
By having this, the code could have testing and performance measurements in it that would be taken out once the code is submitted for the Online Judge for the real test.
I have added this to my code to test the usage:
int main() {
#ifndef ONLINE_JUDGE
Debug (printf("ONLINE_JUDGE not defined\n");)
#else
Debug (printf("ONLINE_JUDGE is defined\n");)
#endif
/* ... rest of the code here ... */
return 0;
}
When I run this in the IDE (CodeChef IDE) it shows the output with “ONLINE_JUDGE is defined” as the first output line (which it should not).
So, am I doing it incorrectly?
Or it is also being set in the IDE (which would be wrong behavior)?
“debug” variable will be true (because of flag above), so it will print “Debug Mode”
I don’t know which code you used like that gave a correct answer, but when I set a problem on SPOJ or Codeforces, it automatically add that flag to complier command
-DONLINE_JUDGE is a compiler directive to add the defined word to the compile. It is the same as having a line of code that says “#define ONLINE_JUDGE” in your program file.
The software behind the IDE and the actual SPOJ judge is the same. There may be some differences in the version of the languages but rest all is same. That is why you see that variable defined at both the places.
We understand that this needed. Right now I am not sure, if this could be done or how much time it will take us to change this, as this is controlled by the SPOJ team. We will ask them and get back to you.
This is expected. Ideally while using local testing, you should write #ifndef ONLINE_JUDGE because you are sure that ONLINE_JUDGE is not define in your local machine, but it is define in codechef.