杭电的OJ系统,在FAQ里就有这个问题:
Q:Is there any way to determine if my program is runned at Online Judge or not ?
A:There is a conditional define of compiler called ONLINE_JUDGE. Example of using:
C/C++
#ifdef ONLINE_JUDGE
running on online judge
#else
you can do something here on your local computer
#endif
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
#endif
int a,b;
while(cin>>a>>b)
cout<<a+b<<endl;
return 0;
}