基于 C++ 的数据生成器

由于不会用也不想学 python 导致每次出题造数据都很不方便,前前后后写了几个基于 C++ 的数据生成器。今天封装了一下,造福以后的自己。

datamaker.cpp

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;

#define int long long

char filename[] = "data1_***.in";
int id_range_l = 1, id_range_r = 20;

mt19937_64 rnd(time(0));
int rd(int l, int r);

void datamaker() {
	
}

signed main() {
	for(int i = id_range_l; i <= id_range_r; i ++) {
		char str[strlen(filename)]; strcpy(str, filename);
		int cnt = 0;
		for(int j = 0; str[j] != '\0'; j ++) { cnt += str[j] == '*'; }
		for(int j = 0; str[j] != '\0'; j ++) {
			if(str[j] != '*') { continue; }
			if(cnt == 3) { str[j] = i / 100 + '0'; }
			if(cnt == 2) { str[j] = i % 100 / 10 + '0'; }
			if(cnt == 1) { str[j] = i % 10 + '0'; }
			cnt --;
		}
		freopen(str, "w", stdout);
		datamaker();
	}
	return 0;
}

int rd(int l, int r) {
	return rnd() % (r - l + 1) + l;
}

runner.cpp

#include<bits/stdc++.h>
#include<windows.h>

using namespace std;

char filename_in[] = "data1_***.in", filename_out[] = "data1_***.out";
int id_range_l = 1, id_range_r = 50;

signed main() {
	for(int i = id_range_l; i <= id_range_r; i ++) {
		char command[100] = "std.exe";
		char str[strlen(filename_in)]; strcpy(str, filename_in);
		int cnt = 0;
		for(int j = 0; str[j] != '\0'; j ++) { cnt += str[j] == '*'; }
		for(int j = 0; str[j] != '\0'; j ++) {
			if(str[j] != '*') { continue; }
			if(cnt == 3) { str[j] = i / 100 + '0'; }
			if(cnt == 2) { str[j] = i % 100 / 10 + '0'; }
			if(cnt == 1) { str[j] = i % 10 + '0'; }
			cnt --;
		}
		strcat(command, " < "), strcat(command, str);
		char str_[strlen(filename_out)]; strcpy(str_, filename_out);
		cnt = 0;
		for(int j = 0; str_[j] != '\0'; j ++) { cnt += str_[j] == '*'; }
		for(int j = 0; str_[j] != '\0'; j ++) {
			if(str_[j] != '*') { continue; }
			if(cnt == 3) { str_[j] = i / 100 + '0'; }
			if(cnt == 2) { str_[j] = i % 100 / 10 + '0'; }
			if(cnt == 1) { str_[j] = i % 10 + '0'; }
			cnt --;
		}
		strcat(command, " > "), strcat(command, str_);
		system(command);
		system("pause");
	}
	return 0;
} 
posted @ 2025-02-23 01:42  Pretharp  阅读(37)  评论(0)    收藏  举报