学了这么久OI连个spj都不会写真是惭愧啊。。。c++
趁着没退役赶忙学一波吧git
github下载地址github
我是直接暴力复制粘贴的。。windows
而后扔到MingW的目录里ide
直接引用就好啦函数
引用testlib.h后,咱们能够从三个地方读入数据ui
inf:输入文件spa
ouf:选手输出命令行
ans:标准输出code
固然,确定不能直接用scanf读入,testlib里内置了不少读入函数
基本上就够用了。。。
一个简单的例子
#include "testlib.h" // main 须要接收命令行参数 int main(int argc, char *argv[]) { // 初始化 checker 环境 —— 解析命令行参数、打开文件…… registerTestlibCmd(argc, argv); // 三个全局变量 inf, ouf, ans 依次为输入、选手输出和参考输出 int pans = ouf.readInt(-2000, 2000); int jans = ans.readInt(); if (pans == jans) quitf(_ok, "The sum is correct."); else quitf(_wa, "The sum is wrong: expected = %d, found = %d", jans, pans); return 0; }
运行的时候须要切换到checker所在的目录,输入如下命令
windows
checker <input-file> <output-file> <answer-file>
Linux
./checker <input-file> <output-file> <answer-file>
根据输出结果能够判断程序的对错
写这篇文章主要是为了记一下容易翻车的地方。。
若是全都读完后仍然显示这个。。。。
zzq给了个解决方案Orz
本身写了个模板
#include "testlib.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 1005 + 10; void YES() { quitf(_ok, "The ans is correct."); } void NO() { quitf(_wa, "The ans is not correct."); exit(0); } void readInf() { } void readOuf() { } void readAns() { } int main(int argc, char *argv[]) { registerTestlibCmd(argc, argv); readInf(); readOuf(); readAns(); return 0; }