【技巧】程序的对拍


今天我们来看一下对拍
对拍是经常用的技巧,拥有在写了暴力后与标程比较比较看看自己的是否正确等等用途

对拍需要的四个物品
baoli.exe , std.exe , date.exe , pai.exe

现在让我们看看具体怎么操作

第一步:一个你的暴力程序


需要cpp生成一个exe才可以

#include<bits/stdc++.h>
using namespace std;
int main()
{
    freopen("data.txt","r",stdin);
    freopen("baoli.out","w",stdout);
    int n;cin>>n;
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        int x;cin>>x;
        tot+=x;
    }
    cout<<tot;
}

第二步:一个std.exe


当然一个std的exe也是必不可少的

#include<bits/stdc++.h>
using namespace std;
int main()
{
    srand(time(0));
    freopen("data.txt","r",stdin);
    freopen("std.out","w",stdout);
    int n;cin>>n;
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        int x;cin>>x;
        tot+=x;
    }
    int t=rand()%3;
    if(t==0) tot++;
    cout<<tot;
}

第三步:数据生成


再生成两个exe之后我们准备比较
现在我们看一下数据生成器

#include<bits/stdc++.h>
using namespace std;
int main()
{
    freopen("data.txt","w",stdout);
    srand(time(0));
    int n=rand()%100+1;
    cout<<n<<endl;
    for(int i=1;i<=n;i++)
    {
        int a=rand()%1000+1;
        cout<<a<<" ";
    }
}


当然这些具体的内容因题目而异,需要自己去调整

第四步:对拍器

最后需要的是对拍器
对拍的直接实现核心

#include<cstdlib>
#include<bits/stdc++.h>
using namespace std; 
int main()
{   int tot=0;
    while(true)
    {
        system("data.exe");
        system("std.exe");
        system("baoli.exe");
        if(system("fc std.out baoli.out"))
        {
            cout<<"WA";
            while(1);
            system("pause");
        }
        tot++;
        cout<<tot;
    }
}

第五步:运行pai.exe,查看结果


所谓对拍就是这样的东西啦,不过每个部分的具体内容需要自己去修改研究,本篇博客中的仅仅是个样例而已233333

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值