testlib.h从入门到入坟

学了这么久OI连个spj都不会写真是惭愧啊。。。

趁着没退役赶紧学一波吧

配置

github下载地址

我是直接暴力复制粘贴的。。

然后扔到MingW的目录里

直接引用就好啦

 

基本语法

引用testlib.h后,我们可以从三个地方读入数据

inf:输入文件

ouf:选手输出

ans:标准输出

当然,肯定不能直接用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

 

 

  •  checker内尽量不要出现中文字符,不然上传到某些OJ的时候可能会出BUG

 

 自己写了个模板

#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;
}
板子
posted @ 2018-09-25 21:57  自为风月马前卒  阅读(6421)  评论(1编辑  收藏  举报

Contact with me