首先我们先建立一个关于生成随机数据的程序
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
const int N=20;
int main()
{
freopen("1.in","w",stdout); //注意文件输出
std::srand(time(NULL));
int n=rand()%N;
printf("%d",n);
for (int i=1;i<=n;i++)
printf("%d ",rand()%N);
puts("");
return 0;
}
其中记住要模数!否则随机化生成的数太大了
然后便是对拍程序的编写
对于windows系统下
对拍程序如下:
#include <bits/stdc++.h>
using namespace std;
int main()
{
while (1)
{
system("maker");
system("true");
system("false");
if (system("fc true.out false.out"))
{
puts("WA");
break;
}
else
puts("宫胁咲良qwq");
}
return 0;
}
对于linux系统下,对拍程序如下:
#include <bits/stdc++.h>
using namespace std;
int main()
{
while (1)
{
system("./maker");
system("./true");
system("./false");
if (system("diff true.out false.out"))
{
puts("WA");
break;
}
else
puts("宫胁咲良qwq");
}
return 0;
}
然后我们建立两个程序为true.cpp和false.cpp
对于这两个程序,我们的读入文件要是随机数那个cpp文件输出的文件
例如我们随机一个快排和一个错误的快排
//true.cpp
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n,a[100001];
int main()
{
freopen("1.in","r",stdin); //注意文件读入
freopen("true.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+n+1);
for (int i=1;i<=n;i++)
printf("%d ",a[i]);
fclose(stdin);
fclose(stdout);
return 0;
}
//false.cpp
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n,a[10001];
int main()
{
freopen("1.in","r",stdin); //注意文件读入
freopen("false.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+n+1);
for (int i=1;i<=n%15;i++)
printf("%d ",a[i]);
fclose(stdin);
fclose(stdout);
return 0;
}