Windows版对拍
cmd 版
mk > 1.in
bf < 1.in > bf.out
test < 1.in > test.out
fc bf.out test.out
if errorlevel==1 pause
%0
bf为暴力算法
text为”正解“
mk为造数据代码
c++版
#include<bits/stdc++.h>
using namespace std;
int main(){
while (1){ //一直循环,直到找到不一样的数据
system("data.exe > in.txt");
system("baoli.exe < in.txt > baoli.txt");
system("std.exe < in.txt > std.txt");
if (system("fc std.txt baoli.txt")) //当 fc 返回 1 时,说明这时数据不一样
puts("WA");
system("pause");
break; //不一样就跳出循环
}
return 0;
}
date为造数据代码。
baoli为暴力代码。
std为”正解“代码
Linux对拍
c++版
#include <algorithm>
using namespace std;
int main(){
int T = 10000;
int tot = 0;
while(T--){
tot++;
cout << tot << " ";
system("./rand; ./std; ./tmp");
if(system("diff std.out tmp.out")){
cout << "WA" << endl;
return 0;
}
else cout << "AC" << endl;
}
}
脚本版
make 1
make a
make b
cnt=1
while true; do
((cnt++))
./1 > IN
#python3 1.py > in
./a < in > a.out
./b < in > b.out
if diff a.out b.out; then
printf "#$cnt Accepted\n"
else
notify-send 'Wrong Answer'
break
fi
done
代码造数据
前置芝士
rand函数
External Player - 哔哩哔哩嵌入式外链播放器
rand的最大值用RAND_MAX求
freopen
External Player - 哔哩哔哩嵌入式外链播放器
freopen("文件名","r/w",stdin/out)
造数据、正解、暴力都要用!!!
造数据代码
造数据
如题目洛谷题目P1001
#include<bits/stdc++.h>
using namspace std;
int rd(){
long long n;
n=rand()*rand()%1000000000;
}
int main(){
int a,b;
a=rd();
b=rd();
cout<<a<<" "<<b;
return 0;
}
加上freopen
#include<bits/stdc++.h>
using namspace std;
int rd(){
long long n;
n=rand()*rand()%1000000000;
return n;
}
int main(){
freopen("1.in","w",stdout);
int a,b;
a=rd();
b=rd();
cout<<a<<" "<<b;
return 0;
}