思维稍乱,重新整理了一下- @echo off
- set "arr=51, 8, 13, 2, 52, 61, 37, 85, 19, 11, 7, 62, 22, 38, 79, 1,2,3"
- set /a range1=102, range2=105
- :main
- setlocal enableDelayedExpansion
- for %%a in (%arr%) do set /a num+=1 & set a[!num!]=%%a
- if %num% gtr 20 echo Are you killing 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!
- )
- )
- for /l %%a in (1 1 %num%) do (
- set /a min=0, max=0
- for /l %%i in (1 1 %%a) do set /a min+=a[%%i], n=num-%%i+1&set /a max+=a[!n!]
- if !min! leq %range2% if !max! geq %range1% (
- rem echo %%a:[!min!,!max!]
- call :Combination %%a %num%
- )
- )
- pause
- endlocal&exit/b
-
- rem 获取组合
- :Combination [num] [len]
- %static% set letters=[abcdefghijklmnopqrstuvwxyz]
- setlocal enableDelayedExpansion
- set /a num=%1, len=%2
- for /l %%a in (1 1 %num%) do (
- set var=!letters:~%%a,1!
- if 1==%%a (
- set "set_start=set start=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,%len%) do "
- set "exp=!exp!,^!a[%%!var!]^!"
- )
- %do% (
- set /a prior=sum, sum=0
- if !prior! leq %range2% (
- for %%a in (%exp%) do set /a sum+=%%a
- if !sum! geq %range1% if !sum! leq %range2% echo%exp:,=+%=!sum!
- )
- )
- endlocal
- goto :eof
复制代码
|