【LittleXi】OJ数据快速生成输入输出项目

该代码实现了一个程序,用于为在线判题系统(OJ)自动创建输入(.in)和输出(.out)文件。它使用随机数生成器创建数据,通过计算最大公约数(GCD)来得到答案,并将结果写入相应文件。程序能批量生成多组测试用例。
摘要由CSDN通过智能技术生成

项目背景

OJ很多题需要造数据,每次手动造非常不方便,于是提出了自动生成1.in,1.out文件的需求

源码

#include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
#include<numeric>
#include<vector>
#pragma warning(disable:4996)
using namespace std;
long long __gcd(long long x, long long y) {
    return y == 0 ? x : __gcd(y, x % y);
}

//输入
vector<int> solve1()
{
	int a = rand() % 1000 + 1;
	int b = rand() % 1000 + 1;
	int c = rand() % 1000 + 1;
	cout << a << endl;
	cout << b << endl;
	cout << c << endl;
	fclose(stdout);
	return { a,b,c };
}
//答案
void solve2(int a,int b,int c)
{
	int d = __gcd(a, b);
	d = __gcd(c, d);
	cout << a * b * c / d;
	fclose(stdout);
}

void generate()
{
	freopen("1.in", "w", stdout);
	auto v = solve1();
	freopen("1.out", "w", stdout);
	solve2(v[0], v[1], v[2]);

	freopen("2.in", "w", stdout);
	 v = solve1();
	freopen("2.out", "w", stdout);
	solve2(v[0], v[1], v[2]);


	freopen("3.in", "w", stdout);
	 v = solve1();
	freopen("3.out", "w", stdout);
	solve2(v[0], v[1], v[2]);


	freopen("4.in", "w", stdout);
	 v = solve1();
	freopen("4.out", "w", stdout);
	solve2(v[0], v[1], v[2]);


	freopen("5.in", "w", stdout);
	 v = solve1();
	freopen("5.out", "w", stdout);
	solve2(v[0], v[1], v[2]);

	freopen("6.in", "w", stdout);
	 v = solve1();
	freopen("6.out", "w", stdout);
	solve2(v[0], v[1], v[2]);

	freopen("7.in", "w", stdout);
	v = solve1();
	freopen("7.out", "w", stdout);
	solve2(v[0], v[1], v[2]);


	freopen("8.in", "w", stdout);
	v = solve1();
	freopen("8.out", "w", stdout);
	solve2(v[0], v[1], v[2]);


	freopen("9.in", "w", stdout);
	v = solve1();
	freopen("9.out", "w", stdout);
	solve2(v[0], v[1], v[2]);


	freopen("10.in", "w", stdout);
	v = solve1();
	freopen("10.out", "w", stdout);
	solve2(v[0], v[1], v[2]);

	freopen("11.in", "w", stdout);
	v = solve1();
	freopen("11.out", "w", stdout);
	solve2(v[0], v[1], v[2]);

	freopen("12.in", "w", stdout);
	v = solve1();
	freopen("12.out", "w", stdout);
	solve2(v[0], v[1], v[2]);


	freopen("13.in", "w", stdout);
	v = solve1();
	freopen("13.out", "w", stdout);
	solve2(v[0], v[1], v[2]);


	freopen("14.in", "w", stdout);
	v = solve1();
	freopen("14.out", "w", stdout);
	solve2(v[0], v[1], v[2]);


	freopen("15.in", "w", stdout);
	v = solve1();
	freopen("15.out", "w", stdout);
	solve2(v[0], v[1], v[2]);

	freopen("16.in", "w", stdout);
	v = solve1();
	freopen("16.out", "w", stdout);
	solve2(v[0], v[1], v[2]);
}


int main()
{
	((unsigned)time(NULL));
	generate();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值