当前位置: 移动技术网 > IT编程>开发语言>C/C++ > testlib.h从入门到入坟

testlib.h从入门到入坟

2018年09月26日  | 移动技术网IT编程  | 我要评论

宋瑞珂,jjvoddy,郑媛媛济宁

学了这么久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;
}
板子

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网