學了這麼久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; }