对拍的入门姿势

数据生成器

/*数据生成器:用于生成20-100000的整数*/
#include<cstdio>
#include<ctime>
#include<cstdlib>
int main()
{
    srand(time(NULL));
    printf("%d %d\n",rand()%100000,rand()%100000);
}

注意:Windows下rand()函数的范围是[0,2^16)

生成字符串:


#include<cstdio>
#include<ctime>
#include<cstdlib>
int main()
{
    srand(time(NULL));
    int len=rand()%30;//长度不超过30
    while(len--)
    {
         printf("%c",rand()%26+'A');
    }
    putchar(10);//换行
}

对拍bat版

(1)新建一个文件夹,将正确程序.exe和测试程序.exe以及数据生成程序.exe放在该文件夹下。
(2)在该文件夹下新建一个文本文档
(3)在文本文档中输入

//模板
:again
data > input.txt 
这里写正确程序的名字.exe < input.txt > 这里写正确程序的名字.txt
这里写测试程序的名字.exe < input.txt > 这里写测试程序的名字.txt
fc 正确程序的名字.txt 测试程序的名字.txt
if not errorlevel 1 goto again
pause

例子:

:again
data > input.txt 
1.exe < input.txt > 1.txt
2.exe < input.txt > 2.txt
fc 1.txt 2.txt
if not errorlevel 1 goto again
pause

(4)把扩展名改为bat,保持在该文件夹下。
(5)运行bat文件即可。

对拍exe版

//注意保证1.exe 、2.exe 和data.exe以及下面程序在一个文件夹下。
//1.exe是正确程序
//2.exe是测试程序
//data.exe是数据程序器
#include <iostream>
#include <windows.h>
#include <cstdio>
using namespace std;
int main()
{
    int t=1000;//d对拍t次
    while(--t)
    {
        system("data.exe > data.txt");
        system("1.exe < data.txt > 1.txt");
        system("2.exe < data.txt > 2.txt");
        if(system("fc 2.txt 1.txt"))
            break;
    }
    if(t==0)
        cout<<"AC"<<endl;
    else
        cout<<"WA"<<endl;
    getchar();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值