项目背景
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();
}