今天一道题卡了很久没找到bug,所以学习了一下对拍,结果成功找到了bug,所以在这里记录一下对拍。
首先三个程序,分别是生成测试数据make.cpp、标程standard.cpp、自己的程序myself.cpp。
make.cpp的数据各种生成方式
范围内的整数:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
srand( time( NULL ) );
int t = 99,n = 10 ;
while( n-- )
{
printf("%d\n",rand() % t );
}
return 0;
}
其中t为最大值。
小数:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
srand( time( NULL ) );
int t,n = 10 ;
while( n-- )
{
printf("%.6lf\n",rand()*1.0 / 100 );
}
return 0;
}
字符串:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
srand( time( NULL ) );
int t = 99,n = 10 ;
while( n-- )
{
printf("%c\n",rand() % 26 + 'A' );
}
return 0;
}
bat的对拍程序写法
写入txt后改后缀为bat,运行即可。无错会一直显示运行下去。ctrl+c可以暂停。
:loop
make.exe > in.txt
standard.exe < in.txt > out1.txt
myself.exe < in.txt > out2.txt
fc /A out1.txt out2.txt
if not errorlevel 1 goto loop
pause
:end