对拍
数据生成
rand()
产生一个随机数(不超过32767)
使用srand()对随机数种子进行初始化
头文件:cstdlib
random_shuffle()
用于打乱一个数组
语法:random_shuffle(a,a+n)
头文件:algorithm
对拍
Windows环境
#include <cstdio> //有些头文件包含了system函数(iostream,cstdio等)
using namespace std;
int main()
{
while (1) //自己控制循环次数
{
system("data.exe > in.txt");
system("std.exe < in.txt > std.txt");
system("mine.exe < in.txt > mine.txt");
if (system("fc std.txt mine.txt")) //当 fc 返回1时,说明这时数据不一样
break; //不一样就跳出循环
}
return 0;
}
Linux环境
//先在每个程序(数据生成器,暴力程序,测试程序)里写文件输入输出
#include <cstdio>
using namespace std;
int main()
{
while (1) //自己控制循环次数
{
system("./data");
system("./mine");
system("./std");
if (system("diff std.txt mine.txt")) break;
}
return 0;
}

浙公网安备 33010602011771号