对拍

对拍

这里先写一种用c++写的对拍程序,其他的以后再补;

一.C++

一共有四个 .exe
用于生成测试数据的 data.exe
正确代码生成的 biaoda.exe
要测试代码生成的 test.exe
以及调用这三者 对拍启动器.exe

!!注意:这三者要放在同一个目录下!!
(我写的程序要在前三个里加上 将数据从文件读入 输出到文件 的语句;相信这对oier都很熟悉了)

1.用于生成测试数据的 data.exe

#include <cstdio>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
	freopen("data.txt","w",stdout); //重新定义输出对象,输出到data.txt
	
	srand(time(0));//这里是设置随机数函数,得到的随机数随时间变化
	srand( (unsigned)time( NULL ) );
	
	int a,b,t,n,k,q;//后面的部分根据题目自己设置,这里为HDU-3577对应的随机数据
	
	t=rand()%10+1;
	printf("%d\n",t);
	for(int i=1;i<=t;i++)
	{
		k=rand()%1000+1;
		q=rand()%100000+1;
		printf("%d %d\n",k,q);
		for(int j=1;j<=q;j++)
		{
			do
			{
				a=rand()%1000000+1;
				b=rand()%1000000+1;
			}
			while(a>=b);
			printf("%d %d\n",a,b);
		}
	}
	
	return 0;
}

同理 test.exebiaoda.exe 都要加上 freopen(); (当然也可以用fopen()之类的);
为了方便给出代码;

2.在 test.exe 代码的 main 函数开头加上

	freopen("data.txt","r",stdin);
	freopen("test.txt","w",stdout);

3.在 biaoda.exe 代码的相同位置加上

	freopen("data.txt","r",stdin);
	freopen("biaoda.txt","w",stdout);

4.调用并对比结果的 对拍启动器.exe

#include<cstdio>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
	int t=0,begintime,endtime;
    while(t<=100000)
    {
    	t++;
		printf("NO.%d \n",t);
		system("data.exe");//运行data.exe
		begintime=clock();
        
        system("biaoda.exe");//运行bioda.exe
        endtime=clock();
        printf("biaoda:运行时间:%d\n",endtime-begintime);
        
        
		begintime=clock(); 
		system("test.exe");//运行test.exe
        endtime=clock();
        printf("test:运行时间:%d\n",endtime-begintime);
        if(system("fc test.txt biaoda.txt"))   system("pause");//对比结果
    }
    system("pause");
    return 0;
}

相信相比较其他操作,这样的方式对于选手们更容易理解吧。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值