对拍(windows&linux)

首先需要3份代码(rand.cpp,my.cpp,spj.cpp)

注意:所有代码都不要freopen

rand.cpp

#include<bits/stdc++.h>
using namespace std;

int get_random_integer(int min, int max) {
    static default_random_engine e((unsigned int) time(nullptr));
    uniform_int_distribution<int> u(min, max);
    return u(e);
}
int main(){
	int T = 1;
	printf("%d\n",T);
	while(T--){
		printf("%d\n",get_random_integer(1,100));
	}
	
	return 0;
} 

准备好3个文件后根据不同系统运行不同的文件就可以

windows(run.bat)

@echo off
:loop
    rand.exe > in.txt
    my.exe < in.txt > myout.txt
    std.exe < in.txt > stdout.txt
    fc myout.txt stdout.txt
if not errorlevel 1 goto loop
pause
goto loop

linux(run.sh)(需要chmod +x run.sh给执行权限)

g++ -o rand rand.cpp
g++ -o my my.cpp
g++ -o std std.cpp
t=0
while true; do
    ((t=t+1))
    ./rand > in.txt
    ./my < in.txt > myout.txt
    ./std < in.txt > stdout.txt

    res=`diff myout.txt stdout.txt`
    if [ -n $res] ; then
        echo "#"$t":AC"
    else
        echo "#"$t":WA"
        echo $res
        exit 1
    fi
done

hustoj使用special judge

spj是一个程序,它可以读取测试输入,测试输出,用户输出来进行答案的正确性判断,spj返回0代表答案正确,返回其他值代表答案错误

下面是一个判断精度的例子

样例输入
2 //T代表组数
50 
100
样例输出
Case 1: 12.9933758002
Case 2: 8.5431270393
用户输出
Case 1: 12.9933758005
Case 2: 8.5431270397

spj.cpp代码

#include <bits/stdc++.h>

const double eps = 1e-6;

int main(int argc, char *args[]) {
    freopen("diff.out", "w", stdout);//这句话可以让spj的输出在wa对比中显示

    FILE *f_in = fopen(args[1], "r");//测试输入
    FILE *f_out = fopen(args[2], "r");//测试输出
    FILE *f_user = fopen(args[3], "r");//用户输出

    int ans = 0;
    int T;
    fscanf(f_in, "%d", &T);//使用fscanf读入
    for (int i = 1; i <= T; i++) {
        int user_id, std_id;
        double user_ans, std_ans;
        fscanf(f_user, "Case %d: %lf", &user_id, &user_ans);
        fscanf(f_out, "Case %d: %lf", &std_id, &std_ans);
        if (user_id != std_id) {
            printf("%d: id is wrong\n", i);
            ans = 1;
        }
        if (fabs(user_ans - std_ans) > eps) {
            printf("%d: ans is wrong\n", i);
            ans = 1;
        }
    }

    return ans;//建议统一出口,方便显示wa对比
}

写完后和数据上传到一个文件夹,进行编译运行测试

g++ -o spj spj.cpp
./spj sample.in sample.out sample.out
echo $?
0 #Accepted
./spj sample.in sample.out sample.in
echo $?
1 #Wrong Answer