rt,一般可以自己写一个朴素的正确程序或者到网上搞一个正解出来跟自己的程序对拍。
以a+b为例
自己写的程序:zj.cpp(zj.exe)
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
暴力程序:bl.cpp(bl.exe)
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
while(b--) a++;
cout<<a<<endl;
return 0;
}
随机数生成器(数据生成):data.cpp(data.exe):
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(0));
int a,b;
a=rand();
b=rand();
cout<<a<<' '<<b<<endl;
//system("pause");
return 0;
}
最后,对拍程序:对拍.cpp(对拍.exe):
#include<iostream>
#include<cstdlib>
#include<windows.h>
using namespace std;
int main()
{
int t=100;
while(t--)
{
system("data > 1.in");
system("zj < 1.in > 1.out");
system("bl < 1.in > 2.out");
if(system("fc 1.out 2.out")) break;
}
system("pause");
return 0;
}
全部生成可执行的exe文件后拖到一个文件夹下面,然后运行 对拍.exe即可。
如果有不同那么此时的1.in就是有问题的输入数据,1.out,2.out,就是输出文件.
可以开心地找错啦~