本帖最后由 wankoilz 于 2011-5-22 11:42 编辑
6楼并非最快吧...
把6楼代码构造成求8个字符40320个组合,且去掉set/a flag+=1,耗时8秒。- @echo off&setlocal enabledelayedexpansion
- set var=a b c d e f g h
- echo %time%
- (for %%i in (!var!) do (
- set var1=!var:%%i=!
- for %%j in (!var1!) do (
- set var2=!var1:%%j=!
- for %%k in (!var2!) do (
- set var3=!var2:%%k=!
- for %%l in (!var3!) do (
- set var4=!var3:%%l=!
- for %%m in (!var4!) do (
- set var5=!var4:%%m=!
- for %%n in (!var5!) do (
- set var6=!var5:%%n=!
- for %%o in (!var6!) do (
- set var7=!var6:%%o=!
- for %%p in (!var7!) do (
- echo %%i %%j %%k %%l %%m %%n %%o %%p
- )))))))))>c.txt
- echo %time%
- pause
复制代码 同样的求8个字符40320个组合,下面的耗时不到4秒:- @echo off&setlocal enabledelayedexpansion
- set/p s=请输入,用一个空格分开:
- echo %time%
- set f1=a.txt
- set f2=b.txt
- >!f1! echo !s:~,1!&set s=!s:~1!
- set len=1
- for %%a in (%s%) do (
- (for /f %%b in (!f1!) do (
- set tmp=%%b
- for /l %%c in (0,1,!len!) do echo !tmp:~,%%c!%%a!tmp:~%%c!
- ))>!f2!
- set t=!f1!
- set f1=!f2!
- set f2=!t!
- set/a len+=1
- )
- echo %time%
- start %f1%&del/f %f2%
- pause
复制代码 我在想for嵌套得太深了是不是会影响效率... |