对拍c++与bat

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

对拍.baticon-default.png?t=N7T8https://www.yuque.com/attachments/yuque/0/2024/bat/45755954/1722998458692-519229f5-33e8-4870-b3ec-76f8ac8a706f.bat

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;
}

对拍c++.cppicon-default.png?t=N7T8https://www.yuque.com/attachments/yuque/0/2024/cpp/45755954/1722998952539-8ddfc309-a187-4e8d-86c6-595f3febc073.cpp

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;
	}
}

对拍c++.cppicon-default.png?t=N7T8https://www.yuque.com/attachments/yuque/0/2024/cpp/45755954/1722999394784-5e4ce01a-53ac-49dd-ad0a-d171fc363091.cpp

脚本版

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

对拍.txt

代码造数据

前置芝士

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;
}

  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值