Generating test data ACM

Just recently the topic so I study a little, C language rand () function does not meet our needs! ! !

  • Reference to some blog, I think this blog to write better! ! ( Click on my visit! )
  • This blog post seems to me to be modified a bit of code! ! Members chiefs, have any questions, leave a comment below! thank!
#include<bits/stdc++.h>
using namespace std;
const string LLMax="9223372036854775807";
const string IntMax="2147483647";
const int intDigit = 10;
const int llDigit = 19;
typedef long long ll;
string randIntNum(int digit, bool isHasZero, bool isGetNegative)
{
   int n = rand() % digit + 1; 	//需要生成的位数 
   string randNumString = "";
   if(n == intDigit){
   	randNumString += (rand() % 2 + 1 + '0');
   	for(int i = 1; i < n; i++){
   		int tmp = rand() % 10;
   		while(tmp > (IntMax[i] - '0')) tmp = rand() % 10;
   		randNumString += (tmp + '0');
   	}
   }
   else if(n == 1){
   	if(isHasZero) randNumString += (rand() % 10 + '0');
   	else randNumString += (rand() % 9 + 1 + '0');
   }
   else{
   	randNumString += (rand() % 9 + 1 + '0');
   	for(int i = 2; i <= n; i++){
   		int tmp = rand() % 10;
   		randNumString += (tmp + '0');
   	}
   }
   
   if(isGetNegative){
   	if(rand() % 2 && randNumString[0] != '0'){
   		randNumString = "-" + randNumString;
   	}	
   }
   return randNumString;
}
string randLLNum(int digit, bool isHasZero, bool isGetNegative)
{
   int n = rand() % digit + 1; 	//需要生成的位数 
   string randNumString = "";
   if(n == llDigit){
   	randNumString += (rand() % 2 + 1 + '0');
   	for(int i = 1; i < n; i++){
   		int tmp = rand() % 10;
   		while(tmp > (LLMax[i] - '0')) tmp = rand() % 10;
   		randNumString += (tmp + '0');
   	}
   }
   else if(n == 1){
   	if(isHasZero) randNumString += (rand() % 10 + '0');
   	else randNumString += (rand() % 9 + 1 + '0');
   }
   else{
   	randNumString += (rand() % 9 + 1 + '0');
   	for(int i = 2; i <= n; i++){
   		int tmp = rand() % 10;
   		randNumString += (tmp + '0');
   	}
   }
   
   if(isGetNegative){
   	if(rand() % 2 && randNumString[0] != '0'){
   		randNumString = "-" + randNumString;
   	}	
   }
   return randNumString;
}
int main()
{
   ios::sync_with_stdio(false);
   freopen("rand.txt", "w", stdout);
   srand(time(0));
   
   return 0;
}

Of course there data generator, which requires batch production data as well as data storage operation, hope the following batch script useful to you! (If you have big brothers with a good program, you can leave a message at the lower share! Thanks!)

  • Tip: rem to comment
  • If you copy the code appears in the case of a line of code to set the ide, and then copy it! ! !
@echo off
set /a index=0
:loop
	rem 数据生成器可执行文件名
	get_rand
	rem 标程可执行文件名
	demo.exe													
	ping 0.0.0.0  -n 2 > null
	set /a index=%index%+1
	echo -----------------------------目前正在处理第%index%个文件---------------------------------
	rem 设置数据文件名
	set name=data%index%.in							
	ren rand.txt %name%
	rem 此处为数据存放路径
	move %name% D:\data					
	rem 设置数据文件名			
	set name=data%index%.out						
	rem 进行移动
	ren demo.txt %name%								
	rem 此处为数据存放路径
	move %name% D:\data								
	::pause
	rem 测试数据生成的组数
	if %index%==100 goto end
	goto loop
:end

Guess you like

Origin blog.csdn.net/HKer_YM/article/details/90735367