``````//01.cpp
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
#define mmset(a,b) memset(a,b,sizeof(a))
using namespace std;
int main()
{

int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
int dx = abs(c - b);
int dy = abs(d - b);
printf("%d\n",max(dx,dy));
return 0;
}``````

1.这时候如果我们想用数据对拍来找bug的话我们可以写一个用bfs思路的正确代码，以下是bfs的正确代码；

``````//02.cpp
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#define ll long long
#define mmset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF = 0x3f3f3f3f;
struct node
{
int x,y,step;
node ()
{
}
node(int p_x,int p_y,int p_step)
{
x = p_x;
y = p_y;
step = p_step;
}
};
int dir[9][2] = {1,0,0,1,-1,0,0,-1,1,1,1,-1,-1,-1,-1,1};
int n,m;
int mark[305][305];
int main()
{
int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
queue <node> que;
que.push(node(a,b,0));
int res = 0;
while(!que.empty())
{
node fro = que.front();
if(fro.x == c && fro.y == d)
{
res = fro.step;
break;
}
que.pop();
for(int i = 0; i < 8; i++)
{
int tx = fro.x + dir[i][0];
int ty = fro.y + dir[i][1];
if(tx >= -100 && tx <= 100 && ty >= -100 && ty <= 100 && mark[tx+105][ty+105] == 0)
{
mark[tx + 105][ty + 105] = 1;
que.push(node(tx,ty,fro.step + 1));
}
}
}
printf("%d\n",res);

return 0;
} ``````

2.如果我们想通过验证输入数据来找出错误数据的话,我们需要讲以上两份代码的输入输出重定向到文件流。

``````//01.cpp
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
#define mmset(a,b) memset(a,b,sizeof(a))
using namespace std;
int main()
{
freopen("input0.in","r",stdin);
freopen("ouput1.out","w",stdout);
int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
int dx = abs(c - b);
int dy = abs(d - b);
printf("%d\n",max(dx,dy));
fclose(stdin);
fclose(stdout);
return 0;
}``````
``````//02.cpp
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#define ll long long
#define mmset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF = 0x3f3f3f3f;
struct node
{
int x,y,step;
node ()
{
}
node(int p_x,int p_y,int p_step)
{
x = p_x;
y = p_y;
step = p_step;
}
};
int dir[9][2] = {1,0,0,1,-1,0,0,-1,1,1,1,-1,-1,-1,-1,1};
int n,m;
int mark[305][305];
template <typename T>
T RandomData(T a, T b,T c)
{
if(c <= b )
{
return rand() % (b - a + 1) +  a;
}
else
{
T temp;
while(true)
{
temp = rand()  % (b - a + 1) + a;
if(temp != c)
{
return temp;
}
}

}
}
int main()
{
freopen("input0.in","r",stdin);
freopen("output2.out","w",stdout);
int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
queue <node> que;
que.push(node(a,b,0));
int res = 0;
while(!que.empty())
{
node fro = que.front();
if(fro.x == c && fro.y == d)
{
res = fro.step;
break;
}
que.pop();
for(int i = 0; i < 8; i++)
{
int tx = fro.x + dir[i][0];
int ty = fro.y + dir[i][1];
if(tx >= -100 && tx <= 100 && ty >= -100 && ty <= 100 && mark[tx+105][ty+105] == 0)
{
mark[tx + 105][ty + 105] = 1;
que.push(node(tx,ty,fro.step + 1));
}
}
}
printf("%d\n",res);
fclose(stdin);
fclose(stdout);

return 0;
} ``````

3.我们需要造出随机数据来作为正确代码和错误代码的输入，然后对别两份代码的输出文件进行寻找错误数据

``````//03.cpp
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include<random>
#include<algorithm>
#include <chrono>
#define ll long long
#define mmset(a,b) memset(a,b,sizeof(a))
using namespace std;
using namespace chrono;
const int INF = 0x3f3f3f3f;
mt19937 rng;  //声明一个随机生成器

template <typename T>
T RandomData(T a, T b,T c)
{
uniform_int_distribution<T> dist6(a, b); //指定范围
if(c > b)
{
return dist6(rng);
}
else
{
T temp;
while(true)
{
temp = dist6(rng);
if(temp != c)
{
return temp;
}
}
}

}

void makeData()
{

FILE* fp=fopen("input0.in","w");
int a = RandomData(-100,100,INF);
int b = RandomData(-100,100,INF);
int c = RandomData(-100,100,INF);
int d = RandomData(-100,100,INF);
fprintf(fp,"%d %d %d %d\n",a,b,c,d);
printf("%d %d %d %d\n",a,b,c,d);
fclose(fp);
}
int main()
{
rng.seed(time(0));     //将时间作为随机生成器随机种子
for(int i = 1; i < 500; i++)
{
makeData();
system("01.exe");
system("02.exe");
printf("Number:%d\n",i);
if(system("fc output1.out output2.out"))
{
printf("Wrong Asnwer\n");
while(1);     //使程序暂停1毫秒
}
}

return 0;
} ``````

1毫秒使得随机种子起作用。

1.三个cpp文件必须在同一文件夹下

2.01.cpp和02.cpp必须通过编译

``````//03.cpp
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include<random>
#include<algorithm>
#include <chrono>
#define ll long long
#define mmset(a,b) memset(a,b,sizeof(a))
using namespace std;
using namespace chrono;
const double INF = 0x3f3f3f3f;
std::mt19937 rng;  //声明一个随机生成器

template <typename T>
T RandomData(T a, T b,T c)
{
uniform_real_distribution<T> dist6(a, b); //指定范围
if(c <= b)
{
return dist6(rng);
}
else
{
T temp;
while(true)
{
temp = dist6(rng);
if(temp != c)
{
return temp;
}
}
}

}

int main()
{

rng.seed(time(0));
while(true)
{
printf("%lf\n",RandomData(-10.0,25.0,INF));
}
return 0;
}``````

``````//03.cpp
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include<random>
#include<algorithm>
#include <chrono>
#define ll long long
#define mmset(a,b) memset(a,b,sizeof(a))
using namespace std;
using namespace chrono;
const double INF = 0x3f3f3f3f;
std::mt19937 rng;  //声明一个随机生成器

template <typename T>
T RandomData(T a, T b,T c)
{
uniform_int_distribution<T> dist6(a, b); //指定范围
if(c <= b)
{
return dist6(rng);
}
else
{
T temp;
while(true)
{
temp = dist6(rng);
if(temp != c)
{
return temp;
}
}
}

}

int main()
{

rng.seed(time(0));
while(true)
{
printf("%c",RandomData('a','y','c'));
}
return 0;
}``````