OI赛制常用代码

· · 个人记录

编译:g++ a.cpp -o a -std=c++14 -Wall -Wshadow -Wextra -O2。

查UB:g++ a.cpp -o a -std=c++14 -Wall -Wshadow -Wextra -O2 -fsanitize=address,leak,undefined。

输入输出重定向:./T1 < qwq.in > qwq.out。

测量时间:time ./a < a.in。

求助:ulimit --help。

stl错误检测:-D_GLIBCXX_DEBUG。

fc(忽略文末空格/回车):diff a.out b.out -Bb

对拍:

#include <cstdio>
#include <cstdlib>

int main() {
  // For Windows
  // 对拍时不开文件输入输出
  // 当然,这段程序也可以改写成批处理的形式
  while (true) {
    system("gen > test.in");  // 数据生成器将生成数据写入输入文件
    system("test1.exe < test.in > a.out");  // 获取程序1输出
    system("test2.exe < test.in > b.out");  // 获取程序2输出
    if (system("fc a.out b.out")) {
      // 该行语句比对输入输出
      // fc返回0时表示输出一致,否则表示有不同处
      system("pause");  // 方便查看不同处
      return 0;
      // 该输入数据已经存放在test.in文件中,可以直接利用进行调试
    }
  }
}