一般的评测机在运行时会加入-DONLINE_JUDGE
,在程序中表现为 宏ONLINE_JUDGE被定义,也就是#ifdef ONLINE_JUDGE
->true
示例
#include <bits/stdc++.h>
#pragma optimize(2)
using namespace std;
int main()
{
#ifdef ONLINE_JUDGE
freopen("2025mmX.in", "r", stdin);
freopen("2025mmX.out", "w", stdout);
#endif
// 输入
// 计算
// 输出
return 0;
}
示例解释
这样在本地调试的时候就不会启用文件输入/输出重定向了