返回列表 发帖
@ECHO OFF&setlocal enabledelayedexpansion
for /l %%i in (0,1,9) do set /a _%%i=%%i+1
for /l %%i in (1,1,4) do (
    for /l %%j in (!_%%i!,1,5) do (
        set /an+=1
        set "$!n!=%%i %%j"
    )
)
for /l %%i in (0,1,9) do (
    for /l %%j in (0,1,9) do (
        set /a "$%%i_%%j=(%%i+%%j)%%10"
    )
)
for /l %%i in (1001,1,1210) do (
    set n=%%i
    md "D:/数据/!n:~1!" 2>nul
)
set n=1000
for /l %%a in (1,1,7) do (
    for /l %%b in (!_%%a!,1,10) do (
        for /l %%c in (!_%%b!,1,10) do (
            for /l %%d in (!_%%c!,1,10) do (
                set /an+=1
                for /l %%e in (100000,1,199999) do (
                    set s=%%e
                    for /f "tokens=1-8" %%1 in ("!$%%a! !$%%b! !$%%c! !$%%d!") do (
                        for /f "tokens=1-4" %%i in ("!s:~%%1,1!_!s:~%%2,1! !s:~%%3,1!_!s:~%%4,1! !s:~%%5,1!_!s:~%%6,1! !s:~%%7,1!_!s:~%%8,1!") do (
                            set /a t=10!$%%i!!$%%j!!$%%k!!$%%l!+1
                            >>"D:/数据/!n:~1!/!t:~1!.txt" set /p =!s:~1! <nul
                        )
                    )
                )
            )
        )
    )
)
pauseCOPY
1

评分人数

TOP

本帖最后由 思想之翼 于 2015-11-8 05:31 编辑

回复 16# terse
感谢您的帮助!
代码正在测试。有些问题还需您的帮助:
1、发现写入的文本数据末尾,没有添加回车符。
2、部分条件形态无数值,没有导入空文本。如果事后添加00001.txt-10000.txt之间未出现序号的空文本,这样的代码如何写?
3、如果是两两相减取绝对值,下句如何修改?
set /a "$%%i_%%j=(%%i+%%j)%%10"

TOP

回复 17# 思想之翼
问题1 问题2
在代码最后 加上
for /l %%i in (1001,1,1210) do (
    set n=%%i
     for /l %%j in (100001,1,110000) do (
         set s=%%j
         >>"D:/数据/!n:~1!/!s:~1!.txt" echo;
     )
)COPY
问题3 将第11行代码 替换为
 set /a "n=%%i-%%j,$%%i_%%j=(n>>31|1)*n"COPY
1

评分人数

TOP

本帖最后由 wankoilz 于 2015-11-9 17:15 编辑

练习awk!
感觉效率是个问题,100000个五位数共2千一百万个组合,仅仅是装入数组就花了34秒
如果再不停的写入文件,估计够呛。
以下代码针对第一个问题,仅仅是将2千一百万个组合装入数组,并没有实现写入文本,因为那样太慢,只当练手。
# & cls & setlocal enabledelayedexpansion
# & cls & echo !time! & echo; | gawk -f %0 >con & echo !time! & pause & exit
END{
     #将100000个“五位数”的共21000000个四位组合装入数组
     s="0123456789"
for(i=1;i<=length(s);i++){arr_num[i]=substr(s,i,1)}
for(a=0;a<=9;a++){
     for(b=0;b<=9;b++){
     for(c=0;c<=9;c++){
     for(d=0;d<=9;d++){
     for(e=0;e<=9;e++){
     str_5=a""b""c""d""e
for(x=1;x<=5;x++){arr_str_5[x]=substr(str_5,x,1)}
str_10=""
for(f=1;f<=5;f++){
     for(g=f+1;g<=5;g++){
     remainder=(arr_str_5[f]+arr_str_5[g]) % 10
     str_10=str_10""remainder
}
}
count_210=0;str_4=""
for(x=1;x<=10;x++){arr_str_10[x]=substr(str_10,x,1)}
for(m=1;m<=10;m++){
     for(n=m+1;n<=10;n++){
     for(o=n+1;o<=10;o++){
     for(p=o+1;p<=10;p++){
     count_210+=1
     str_4=arr_str_10[m]""arr_str_10[n]""arr_str_10[o]""arr_str_10[p]
     arr_rem_com[str_5][count_210]=str_4
}
}
}
}
}
}
}
}
}
#测试查看19999的210个组合情况
for(i=1;i<=210;i++){
     print arr_rem_com[19999][i]
}
}COPY
gawk 4.1.0 下载地址:http://www.bathome.net/viewthread.php?tid=21366&highlight=gawk
为什么代码显示出的缩进会这么大....实际没这么夸张

TOP

回复 18# terse
感谢您的热心帮助!
在末尾添加如下代码  可以在001-210文件夹里  添加00001-10000之间未出现名称的空文本  然后全部文本添加回车符
如果要在001-210文件夹里所有文本数据末尾先添加回车符  然后再在001-210文件夹里添加00001-10000之间未出现名称的空文本,下列代码如何修改?
for /l %%i in (1001,1,1210) do (
    set n=%%i
     for /l %%j in (100001,1,110000) do (
         set s=%%j
         >>"D:/数据/!n:~1!/!s:~1!.txt" echo;
     )
)

TOP

回复 20# 思想之翼

已经添加

TOP

回复 21# terse

您给出的代码,是先添加未出现名称的空文本,再在所有文本中添加回车符,这样先前添加的空文本,也加了回车符
如果先在文本数据末尾添加回车符 ,再添加未出现名称的空文本,您给出的代码如何修改?

TOP

回复 22# 思想之翼

那就加个判断
if exist "D:/数据/!n:~1!/!s:~1!.txt" (>>"D:/数据/!n:~1!/!s:~1!.txt" echo;) else >"D:/数据/!n:~1!/!s:~1!.txt" echo; COPY
1

评分人数

TOP

返回列表