C++ system运行带空格的.exe文件 以及 oi、acm中的一种对拍写法

不带空格的.exe文件写法:

system("work.exe");

上面的方式相信大家都会,但当文件名含空格的时候,像下面这么写就会出问题

system("work 2.exe");

会报以下错误:

'work' 不是内部或外部命令,也不是可运行的程序

解决办法:添加 \" 、\" 将文件名括起来,代码如下。

system(" \"work 2.exe\" ");

应用(代码对拍实例)

CF1359D 为例

make_data.cpp (造数据程序)

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	srand((unsigned)time(nullptr));
	int n = 1 + rand() % 10;
	cout << n << "\n";
	for (int i = 1; i <= n; i++) {
		cout << (rand() % 31) * (rand()%2?1:-1) << ' '; 
	}
	cout << "\n";
	return 0;
}

baoli.cpp (暴力程序)

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j++) {
			int Max = -30, sum = 0;
			for (int k = i; k <= j; k++) Max = max(Max, a[k]), sum += a[k];
			ans = max(ans, sum - Max);
		}
	}
	cout << ans << "\n";
	return 0;
}

D. Yet Another Yet Another Task.cpp (待对拍程序)

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= 30; i++) {
		int tmp = 0;
		for (int j = 1; j <= n; j++) {
			if (a[j] > i) {
				tmp = 0;
				continue;
			}
			else {
				if (tmp > 0) tmp += a[j];
				else tmp = a[j];
			}
			ans = max(ans, tmp - i);
		}
	}
	cout << ans << "\n";
	return 0;
}

duipai.cpp (对拍程序)

#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	for (int i = 1;;i++) {
		cout << i << ":" << endl;
		system("make_data.exe > input.txt");
		system("baoli.exe < input.txt > output.txt");
		system(" \"D. Yet Another Yet Another Task.exe\" < input.txt > my.txt");
		if (system("fc output.txt my.txt")) break;
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值