最近刚好在出题所以就研究了一下,C语言函数rand() 并不能满足我们的需求!!!
参考了一些博客,我觉得还是这篇博文写的比较好!!(点击我访问! ) 看来这篇博文后我对作者的代码加以修改了一下!!各位大佬,有问题可以在下方留言!感谢!
#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 ;
}
当然有了数据生成器,这需要批量生成数据以及对数据进行存储操作,希望下面的批处理脚本对你有用!(如果大佬有跟好的方案,可以下留言处分享!感谢了!)
提示 : rem 为注释 如果复制出现代码都在一行的情况,请将代码在到ide中,然后再复制即可!!!
@echo off
set /a index=0
:loop
rem 数据生成器可执行文件名
get_rand.exe
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