testlib.h從入門到入墳

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

 

 

  •  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;
}
板子
相關文章
相關標籤/搜索