- @echo off&setlocal enabledelayedexpansion
- set "Tab= "这里替换为TAB键
- :lp
- set _n=&set "var="
- set /p var=请输入三个杯的大小(空格分隔):
- set /p _n=输入你要分出的量:
- cls&call :nt %var%
- :nt
- if "%_n%"=="" echo;输入错误&goto lp
- if "%3"=="" echo;输入错误&goto lp
- if not "%4"=="" echo;输入错误&goto lp
- for /f "delims=0123456789 " %%i in ("%var%%_n%") do set var=var
- if "%var%"=="var" echo;输入错误&goto lp
- for %%i in (%var%) do set /a n+=1&set a!n!=%%i
- for /l %%i in (1,1,2) do (
- set /a z=%%i+1
- for /l %%j in (!z!,1,3) do (
- if !a%%i! gtr !a%%j! set/a a%%j=!a%%i!,a%%i=!a%%j!
- )
- )
- for /l %%i in (3,-1,1) do set a%%i=!a%%i!
- set/a a=a3,b=a2,c=a1,x=0,yb=a-b-c,n=0
- if %yb% lss 0 (set/a y=a-b)else set/a y=c
- echo;你要分出的量: %_n%
- echo;%Tab%%a% %Tab%%b%%Tab%%c%
- echo;&echo;初始%Tab%%a%%Tab%0%Tab%0&echo;
- set/a a1=a,a2=0,a3=0
- call:next %b% %c% %y%
- if %yb% lss 0 (set/a y=a-c)else set/a y=b
- echo;&echo;初始%Tab%%a%%Tab%0%Tab%0&echo;
- set/a a1=a,a2=0,a3=0,n=0
- call:next %c% %b% %y%
- pause&exit
- :next
- set/a n+=1
- if %a2% equ 0 (
- if %a3% equ %2 echo 不能分出你要的量&pause&exit
- if %a3% geq %3 (set /a a2=%1-a3+%3) else set/a a2=%1
- ) else (
- if %a3% leq %3 (
- set/a a2-=%2-a3,a3=%2
- if !a2! leq 0 set /a a3+=a2,a2=0
- )
- if %a3% geq %3 set a3=0
- )
- set/a a1=a-a2-a3
- echo 第%n%次%Tab%%a1% %Tab%%a2%%Tab%%a3%
- if /i "%flag%"=="f" set "flag="&exit/b
- if %a1% equ %_n% (set flag=f)else if %a2% equ %_n% (set flag=f)else if %a3% equ %_n% set flag=f
- goto next
复制代码
|