首先,对拍是个好东西。
需要一个保证正确输出的代码,我们将它命名为 r i g h t . c p p right.cpp right.cpp
e.g.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cout<<a+b;
return 0;
}
然后将你的代码,命名为 m i n e . c p p mine.cpp mine.cpp
e.g.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
printf("%d",a+b);
return 0;
}
然后需要一个数据生成代码,命名为 r a n d . c p p rand.cpp rand.cpp
e.g.
#include<bits/stdc++.h>
using namespace std;
int main()
{
srand(time(0));
int a,b;
a=rand()%100+1,b=rand()%100+1;
printf("%d %d\n",a,b);
return 0;
}
最后需要一个对拍的代码 ,我们将它命名为 k i n g . c p p king.cpp king.cpp
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
for(int t=1; t<=1000; t++)
{
printf("NO.%d\n",t);
system("rand.exe > rand.txt");
system("right.exe < rand.txt > right.txt");
system("mine.exe < rand.txt > mine.txt");
if(system("fc mine.txt right.txt"))
{
puts("error");
break;
}
else puts("PASS%%%%");
}
return 0;
}
保证他们都在同一个文件夹中
编译运行 right.cpp rand.cpp mine.cpp
生成 right.exe rand.exe mine.exe
然后运行 king.cpp
(各个cpp的输出数据会保存在各个的txt文件中)