如何对拍数据

1对拍程序

(注意对拍程序中的文件名,要与两个被测程序和数据生成器的名字相同,而且要与这三个程序源码中的名字相同,

如在数据生成器main开头写上freopen("temp.in","w",stdout);

ac程序main开头写上   freopen("temp.in","r",stdin);   freopen("tempac.in","w",stdout);

被检测程序main开头写   freopen("temp.in","r",stdin);   freopen("temp.out","w",stdout);


1)ubuntu (用shell脚本),将对拍程序写到文档里,然后将文档命名为  nick.sh  然后再将另三个执行程序复制过来,并在此打开终端,执行

sh ./nick.sh

对拍程序

#!bin/bash  ubuntu
while true;
do
./make1>temp.in                                       # 此为注释,将名为make1的数据生成器生成的数据导入temp.in文件中
./programac<temp.in>tempac.out        #将temp.in文件中的数据,导入名为programac的ac过的执行程序中,并将生成的数据导入名为tempac.out的文件中
./program<temp.in>temp.out                #将temp.in文件中的数据,导入名为programac的ac过的执行程序中,并将生成的数据导入名为temp.out的文件中
if diff tempac.out temp.out;then            #如果两个输出文件不同,那么就输出第二个文件中(与第一个)不同的部分,并在输出结束后输出WA;如果输出一直相同,则一直输出AC,程序不断继续生成数据直到发现不同
echo AC
else
echo WA
exit 0
fi                                                                  #if 结束
done                                                            #do/while 结束

2)windows (先执行两个程序生成数据后,用下面这个bat批处理文件比较,有不同会停止)

可以先生成数据,然后两个程序分别生成输出文件,然后用bat比较

@echo off
fc tempac.out temp.out
pause


或者 将三个exe复制出来放到同一目录下,执行bat

@echo off
:Loop
 
	MAKEDARA.exe>1.in
	A.exe<1.in>1.ans
	B.exe<1.in>2.ans

	fc A.ans B.ans
	
	if errorlevel 0 goto loop
 pause



2数据生成器,(如何产生随机数一节转载自Lvsi‘s home)

1)产生任意范围的数

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
    //freopen( "1.in","r",stdin );
    freopen("3.out","w",stdout );
    srand( time( NULL ) );
    int t = 99,n = 10 ;
    while( n-- )
    {
           printf("%d\n",rand() % t );
           }
    return0;
}

2)产生int型随机数

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
    //freopen( "1.in","r",stdin );
    //freopen( "3.out","w",stdout );
    srand( time( NULL ) );
    int t,n = 10 ;
    while( n-- )
    {
           printf("%d\n",rand() );
           }
    return0;
}


3)产生随机小数

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
    //freopen( "1.in","r",stdin );
    //freopen( "3.out","w",stdout );
    srand( time( NULL ) );
    int n = 10 ;
    while( n-- )
    {
           printf("%.6lf\n",rand()*1.0 / 100 );
           }
    return0;
}



4)产生字符串

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
int main( )
{
    //freopen( "1.in","r",stdin );
    freopen("3.out","w",stdout );
    srand( time( NULL ) );
    int t = 99,n = 10 ;
    while( n-- )
    {
           printf("%c\n",rand() % 26 +'A');
           }
    return0;
}
(博客:嚜寒)

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值