数据生成器
/*数据生成器:用于生成2个0-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;
}