思维形成定势了,果然有纰漏。稍作改造如下:- @echo off
- set "arr=51, 8, 13, 2, 52, 61, 37, 85, 19, 11, 7, 62, 22, 38, 79"
- set /a min=102, max=105
- :main
- setlocal enableDelayedExpansion
- %const% set MAXNUM=20
- for %%a in (%arr%) do set /a num+=1 & set a[!num!]=%%a
- if %num% gtr %MAXNUM% echo Are you kidding me?&pause&exit /b %num%
- rem 冒泡排序
- for /l %%i in (1 1 %num%) do (
- set /a start = %%i + 1
- for /l %%j in (!start! 1 %num%) do if !a[%%i]! gtr !a[%%j]! (
- set tmp=!a[%%i]!
- set a[%%i]=!a[%%j]!
- set a[%%j]=!tmp!
- )
- )
- rem 为枚举组合数生成for嵌套语句
- set letters=[abcdefghijklmnopqrstuvwxyz]
- for /l %%a in (1 1 %MAXNUM%) do (
- set var=!letters:~%%a,1!
- if 1==%%a (
- set "set_start=set /a start=00+1"
- ) else (
- set /a base=%%a-1
- for %%i in (!base!) do set base=!letters:~%%i,1!
- set "set_start=set /a start=%%!base!+1"
- )
- set "do=!do!!set_start! & for /l %%!var! in (^!start^!,1,^!num^!) do "
- set "exp=!exp!,^!a[%%!var!]^!"
- )
- rem echo !do!
- rem echo !exp!
- rem pause
- for /l %%a in (1 1 %num%) do (
- set /a minsum=0, maxsum=0
- for /l %%i in (1 1 %%a) do set /a minsum+=a[%%i], n=num-%%i+1&set /a maxsum+=a[!n!]
- rem echo %%a:[!minsum!,!maxsum!]
- if !minsum! leq %max% if !maxsum! geq %min% (
- set /a do_len=54*%%a, exp_len=8*%%a
- call:enum
- )
- )
- pause
- endlocal&exit/b
-
- :enum
- setlocal enableDelayedExpansion
- set do=!do:~0,%do_len%!
- set exp=!exp:~0,%exp_len%!
- %do% (
- set /a sum=0%exp:,=+%
- if !sum! geq %min% if !sum! leq %max% echo%exp:,=+%=!sum!
- )
- endlocal
- goto :eof
复制代码
|