方法是 将表上所有数字之和除2 算出一半数字之和
再从1开始加6个数.如果和等于表上一半数字之和 就输出这6个数- @echo off&setlocal enabledelayedexpansion
- for /l %%i in (1 1 12) do (
- set /a a+=%%i
- )
- set /a n=%a%/2
- :lp
- for /l %%j in (1 1 6) do (
- set /a b+=1
- set c=!b!
- for /l %%k in (1 1 6) do (
- set /a c+=1
- set /a d+=!c!
- if !d! equ %n% (goto ak)
- )
- )
- :ak
- set /a num=!b!+1
- echo. 应切分为:
- for /l %%l in (1 1 6) do (
- set /a num+=1
- echo !num!
- )
- pause
复制代码
- ::这是随机取值版本.比较费时间
- @echo off&setlocal enabledelayedexpansion
- set/a a=(1+12)*12/4/3
- :lp
- set/a b=%random%%%12+1
- set/a c=%random%%%12+1
- set/a d=%b%+%c%
- set/a e=%b%-%c%
- if %d% equ %a% (
- if %e% equ 5 (goto end) else goto lp
- ) else goto lp
- :end
- echo.应切分为:
- set/p=!c!<nul
- for /l %%i in (1 1 5) do (
- set/a f=%c%+%%i
- set/p=!f!<nul
- )
- pause
复制代码
- ::这个是取差值版本
- @echo off&setlocal enabledelayedexpansion
- set/a a=(1+12)*12/4/3
- :lp
- for /l %%i in (1 1 12) do (
- set/a b=%%i+5
- set/a c=!b!+%%i
- if !c! equ !a! (goto end)
- )
- :end
- echo.应切分为:
- echo !b!
- for /l %%j in (1 1 5) do (
- set/a b-=1
- echo !b!
- )
- pause
复制代码
[ 本帖最后由 a590687 于 2010-1-9 14:47 编辑 ] |