首先下载这个
把里面的 testlib.h
扔到Dev的 \MinGW32\i686-w64-mingw32\include
里面就可以正常引用了。
引用方法是 include"testlib.h"
如果是在考试中验证自己的程序是否正确,只需要运行一次 checker.cpp
得到 checker.exe
,然后在命令行中输入
./checker in.txt out.txt ans.txt(Linux)
checker.exe in.txt out.txt ans.txt(Windows)
其中in.txt
out.txt
ans.txt
分别是放在同一目录下的输入文件、选手输出、标准答案。
程序将返回结果,示例:
如果是出题人要写SPJ的话,就需要了解 testlib.h
的常用操作。
给出上面压缩包里的一个样例:
#include "testlib.h"
#include <stdio.h>
#include <math.h>
const double EPS = 1.5E-6;
int main(int argc, char * argv[])
{
setName("compare two doubles, maximal absolute error = %.10f", EPS);
registerTestlibCmd(argc, argv);
double ja = ans.readDouble();
double pa = ouf.readDouble();
if (fabs(ja - pa) > EPS + 1E-15)
quitf(_wa, "expected %.10f, found %.10f", ja, pa);
quitf(_ok, "answer is %.10f", ja);
}
读入
可以从这三个结构体中读入:
inf (输入文件)
ouf (输出文件)
ans (标准答案)
(引用洛谷)
以下读入命令可以使用:
void registerTestlibCmd(argc, argv)//初始化 checker,必须在最前面调用一次。
char readChar()//读入一个 char,指针后移一位。
char readChar(char c)//和上面一样,但是只能读到一个字母 c
char readSpace()//同 readChar(' ').
string readToken()//读入一个字符串,但是遇到空格、换行、eof 为止
long long readLong()//读入一个 longlong/int64
long long readLong(long long L, long long R)//同上,但是限定范围(包括 L,R)
int readInt()//读入一个 int
int readInt(int L, int R)//同上,但是限定范围(包括 L,R)
double readReal()//读入一个实数
double readReal(double L, double R)//同上,但是限定范围(包括 L,R)
double readStrictReal(double L, double R, int minPrecision, int maxPrecision)//读入一个限定范围精度位数的实数。
double readDouble()//读入一个实数
double readDouble(double L, double R)//同上,但是限定范围(包括 L,R)
string readString()
string readLine()//读入一行 string,到换行或者 eof 为止
void readEoln()//读入一个换行符
void readEof()//读入一个 eof
输出
quitf(_ok, "The answer is correct. answer is %d", ans);//给出 AC
quitf(_wa, "The answer is wrong: expected = %f, found = %f", jans, pans);//给出 WA
quitp(0.5,"Partially Correct get %d percent", 50);//给出 PC(Partially Correct),并且可以获得该点 50% 的分数
当你需要在洛谷上传附带SPJ的题目时,直接将 checker.cpp
(必须这个名字)塞入测试数据的压缩包内然后上传,并且记得给题目加上标签 Special Judge
。
在 checker.cpp
中,你可以引用其他库并使用他们的函数。
给出 OI Wiki 中对使用 testlib.h 写 checker 的链接。