首先下載這個
把里面的 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 的鏈接。