Loading

程序对拍

一. 对拍

程序对拍就是使用暴力解的结果和其他解的结果进行对比。
这里需要三种程序:1. 随机生成数据的程序;2. 其他解程序; 3. 暴力解程序

@echo off 
:loop 
    create.exe > in.txt
    main.exe < in.txt > myout.txt
    test.exe < in.txt > stdout.txt
    fc myout.txt stdout.txt
if not errorlevel 1 goto loop 
pause
goto loop

其中create.exe是生成数据的程序,main.exe是待测试的程序,test.exe是暴力解程序

create.exe > in.txt

将数据写入in.txt

main.exe < in.txt > myout.txt
test.exe < in.txt > stdout.txt

从in.txt里读取数据,并输出到两个不同的文件中

fc myout.txt stdout.txt

对比两个txt文件

C:\Documents\programfile\mainhello>fc myout.txt stdout.txt
正在比较文件 myout.txt 和 STDOUT.TXT
FC: 找不到差异

如果找到差异就会输出,差异附件的两行内容。

对拍程序编写

编写对拍程序主要就是随机数的运用,具体格式可以根据题目需求来看

#include<cstdlib>
#include<ctime>
#include <iostream>
#include <math.h>

using namespace std;


int rand_with_range(int n){

    return rand()%(n+1);

}

int main(){
	srand((unsigned)time(NULL));

    int r = rand_with_range(pow(10,6));
    int y = rand_with_range(pow(10,6));
    int g = rand_with_range(pow(10,6));
    cout<<r<<" "<<y<<" "<<g<<endl;
    int n = rand_with_range(pow(10,2));
    cout<<n<<endl;
    for(int i = 0; i < n;i++){
    	int op = rand_with_range(3);
    	int t;
    	if(op == 0){
    		t =  rand_with_range(pow(10,6));
		}else if(op == 1){
			t =  rand_with_range(r);
		}else if(op == 2){
			t =  rand_with_range(y);
		}else{
			t =  rand_with_range(g);
		}
		cout<<op<<" "<<t<<endl;
	}

}
posted @ 2020-12-24 15:12  有人找你  阅读(81)  评论(0编辑  收藏  举报