C++生成题目样例文件的代码

//#pragma GCC optimize(2)
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<cstring>
#include<list>
#include<fstream>
#include <random>
#define int long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef  pair<int, int> PII;
const int N = 1e6 + 7;



void solve()
{
	int t = 1;   //测试样例的数量
	int n, m;  //m<=x<=n,确定数据范围
	n = 1e9+7;
	m = 1e8 + 7;
	std::random_device rd;    
	std::mt19937_64 eng(rd()); 
	std::uniform_int_distribution<unsigned long long> distr(m,n);
	while (t < 100)
	{
		string fileName1 = "", fileName2 = "";   //两个文件的名字与位置
		fileName1 += "D:\\题目数据\\stringcin\\";   //文件位置
		string tmp = to_string(t);   //int 转string
		fileName1 += tmp;  //数据编号
		fileName1 += ".in";   //加上后缀
		fileName2 += "D:\\题目数据\\stringcin\\";
		fileName2 += tmp;
		fileName2 += ".out";
		int x = distr(eng);   //随机数
		ofstream lout(fileName1.c_str());//将fileName转化为c型字符串作为文件名
		ofstream rout(fileName2.c_str());
		lout << x << " " << x + 2 << endl;  //往文件里加东西
		rout << x + 2 << " " << x << endl;
		t++;
	}
}

signed main()
{
	//std::ios::sync_with_stdio(false);
	//cin.tie(0), cout.tie(0);
	solve();
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值