windows下的对拍

首先需要新建一个对拍文件夹,在该文件夹下建立源程序,需要对拍的程序,数据生成器,还有对拍程序文件。

例如我们接下来要对拍一个A+B的程序:

//这是我们的程序,命名为my.cpp
#include<iostream>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	while (b--) a++;
	cout << a;
	return 0;
}
//这是源程序,命名为std.cpp
#include<iostream>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << a+b;
	return 0;	
} 
//数据生成器,命名为data.cpp
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;

int main() {
	srand(time(0));//以当前时间点初始化随机数种子
	int a = rand()%100+1, b = rand()%100+1;//1-100内的随机数
	cout << a << " " << b;
	return 0;
}
//对拍程序,命名为check.cpp
#include<iostream>
#include<cstdlib>
using namespace std;

int main() {
	int t = 10;//对拍十组
	while (t--) {
		system("data.exe>data.txt");
		system("my.exe<data.txt>my.txt");
		system("std.exe<data.txt>std.txt");
		if (system("fc std.txt my.txt")) {
			cout <<"error" << endl;
			break;
		}
		else cout << "no error" << endl;
	}
	return 0;
}

要对拍时需要将my和std以及data先编译,然后在编译check,最后运行check可执行程序即可。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值