对拍(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

留下评论

电子邮件地址不会被公开。 必填项已用*标注