复制代码
- @echo off&&color f2&&title SYBN 24点自动计算脚本 V0.2&&setlocal enabledelayedexpansion
- set ff1=^*
- set ff2=^+
- set ff3=^-
- set ff4=^/
- set S1=1
- set S2=2
- set S3=3
- set S4=4
- : begain
- set b1=0
- set b2=1
- set b3=1
- set SS=1
- set XS=1
- set cf=1
- set cs=0
- set c1=0
- set c2=0
- set c3=0
- set c4=0
- set c5=0
- set c6=0
- echo ============= .: SYBN 24点自动计算脚本 V0.2 :. ==============
- echo 请依次输入要用于计算的4个数字,并以空格隔开.例如输入:"1 2 3 4".
- set /p p=[默认: %S1% %S2% %S3% %S4%]:
- for /f "tokens=1,2,3,4,*" %%a in ("%p%") do if not "%%b" == "" set /a S1=%%a&& set /a S2=%%b&& set /a S3=%%c&& set /a S4=%%d&&if not "%%e" == "" set /a SS=%%e
- if %S1% lss 1 goto wx
- if %S2% lss 1 goto wx
- if %S3% lss 1 goto wx
- if %S4% lss 1 goto wx
- if %S1% gtr 13 goto wx
- if %S2% gtr 13 goto wx
- if %S3% gtr 13 goto wx
- if %S4% gtr 13 goto wx
- if %SS% == 543001 echo on&&set SS=1
- if %S1% == %S2% set /a cf=cf+1
- if %S1% == %S3% set /a cf=cf+1&&set /a S5=S2&&set /a S2=S3&&set /a S3=!S5!
- if %S2% == %S3% if not %S1% == %S2% set /a cf=cf+1&&set /a S5=S1&&set /a S1=S3&&set /a S3=!S5!
- if %S1% == %S4% set /a cf=cf+1&&set /a S5=S4&&set /a S4=S3&&set /a S3=S2&&set /a S2=!S5!
- if %S2% == %S4% set /a cf=cf+1&&set /a S5=S4&&set /a S4=S3&&set /a S3=S1&&set /a S1=!S5!
- if %S3% == %S4% if %S2% == %S3% set /a cf=4
- if %S3% == %S4% if not %S2% == %S3% set /a cf=5
- ::echo %S1% %S2% %S3% %S4% %SS% %cf%
- ::pause
- : pl
- set /a b1=b1+1
- if %b1% gtr 4 set /a b1=1&& set /a b2=b2+1
- if %b2% gtr 4 set /a b2=1&& set /a b3=b3+1
- if %b3% gtr 4 echo 无解!&& goto begain
- set f1=!ff%b1%!
- set f2=!ff%b2%!
- set f3=!ff%b3%!
- if %b2% == 1 title 正在计算^-
- if %b2% == 2 title 正在计算^\
- if %b2% == 3 title 正在计算^|
- if %b2% == 4 title 正在计算^/
- if %cf% == 4 (
- call :js %S1% %S1% %S1% %S1% %f1% %f2% %f3%
- goto pl
- )
- if %cf% == 3 (
- call :js %S1% %S1% %S1% %S4% %f1% %f2% %f3%
- call :js %S1% %S1% %S4% %S1% %f1% %f2% %f3%
- call :js %S1% %S4% %S1% %S1% %f1% %f2% %f3%
- call :js %S4% %S1% %S1% %S1% %f1% %f2% %f3%
- goto pl
- )
- if %cf% == 5 (
- call :js %S1% %S1% %S3% %S3% %f1% %f2% %f3%
- call :js %S1% %S3% %S1% %S3% %f1% %f2% %f3%
- call :js %S1% %S3% %S3% %S1% %f1% %f2% %f3%
- call :js %S3% %S1% %S1% %S3% %f1% %f2% %f3%
- call :js %S3% %S1% %S3% %S1% %f1% %f2% %f3%
- call :js %S3% %S3% %S1% %S1% %f1% %f2% %f3%
- goto pl
- )
- call :js %S1% %S2% %S3% %S4% %f1% %f2% %f3%
- call :js %S1% %S2% %S4% %S3% %f1% %f2% %f3%
- call :js %S1% %S3% %S2% %S4% %f1% %f2% %f3%
- call :js %S1% %S3% %S4% %S2% %f1% %f2% %f3%
- call :js %S1% %S4% %S2% %S3% %f1% %f2% %f3%
- call :js %S1% %S4% %S3% %S2% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S2% %S1% %S3% %S4% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S2% %S1% %S4% %S3% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S2% %S3% %S1% %S4% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S2% %S3% %S4% %S1% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S2% %S4% %S1% %S3% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S2% %S4% %S3% %S1% %f1% %f2% %f3%
- call :js %S3% %S1% %S2% %S4% %f1% %f2% %f3%
- call :js %S3% %S1% %S4% %S2% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S3% %S2% %S1% %S4% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S3% %S2% %S4% %S1% %f1% %f2% %f3%
- call :js %S3% %S4% %S1% %S2% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S3% %S4% %S2% %S1% %f1% %f2% %f3%
- call :js %S4% %S1% %S2% %S3% %f1% %f2% %f3%
- call :js %S4% %S1% %S3% %S2% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S4% %S2% %S1% %S3% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S4% %S2% %S3% %S1% %f1% %f2% %f3%
- call :js %S4% %S3% %S1% %S2% %f1% %f2% %f3%
- if not %cf% == 2 call :js %S4% %S3% %S2% %S1% %f1% %f2% %f3%
- goto pl
- : wx
- title 对不起,您输入的数字无效,请重新输入.
- goto begain
- :js
- if %XS% gtr %SS% goto begain
- set /a j=100*(%1%5%2%6%3%7%4) 2>nul
- set X=%1%5%2%6%3%7%4
- if %j% == 2400 call :24 &&goto :EOF
- set /a j=100*((%1%5%2)%6%3%7%4) 2>nul
- set X=(%1%5%2)%6%3%7%4
- if %j% == 2400 call :24 &&goto :EOF
- set /a j=100*(%1%5(%2%6%3)%7%4) 2>nul
- set X=%1%5(%2%6%3)%7%4
- if %j% == 2400 call :24 &&goto :EOF
- set /a j=100*(%1%5%2%6(%3%7%4)) 2>nul
- set X=%1%5%2%6(%3%7%4)
- if %j% == 2400 call :24 &&goto :EOF
- set /a j=100*((%1%5%2%6%3)%7%4) 2>nul
- set X=(%1%5%2%6%3)%7%4
- if %j% == 2400 call :24 &&goto :EOF
- set /a j=100*((%1%5%2)%6(%3%7%4)) 2>nul
- set X=(%1%5%2)%6(%3%7%4)
- if %j% == 2400 call :24 &&goto :EOF
- set /a j=100*(%1%5(%2%6%3%7%4)) 2>nul
- set X=%1%5(%2%6%3%7%4)
- if %j% == 2400 call :24 &&goto :EOF
- set /a j=100*(((%1%5%2)%6%3)%7%4) 2>nul
- set X=((%1%5%2)%6%3)%7%4
- if %j% == 2400 call :24 &&goto :EOF
- set /a j=100*((%1%5(%2%6%3))%7%4) 2>nul
- set X=(%1%5(%2%6%3))%7%4
- if %j% == 2400 call :24 &&goto :EOF
- set /a j=100*(%1%5((%2%6%3)%7%4)) 2>nul
- set X=%1%5((%2%6%3)%7%4)
- if %j% == 2400 call :24 &&goto :EOF
- set /a j=100*(%1%5(%2%6(%3%7%4))) 2>nul
- set X=%1%5(%2%6(%3%7%4))
- if %j% == 2400 call :24 &&goto :EOF
- goto :EOF
- :24
- if %j% == 2400 (
- echo 计算完成,结果:"%X%"^=24
- set /a XS=XS+1
- goto :EOF
- )
- goto :EOF
回复:【精品】我也来写批处理 ...
@echo off
setlocal enableextensions enabledelayedexpansion
title 作者:liuzhaonan11
echo 批处理算24点&echo.
:loop
set /p "n=输入四个数用空格分开: "
set /a "lzn=0"
for %%i in (!n!) do set /a "lzn+=1"&set /a "lz!lzn!z=%%i,lz!lzn!m=1,lz!lzn!s=%%i"
call:liuzhaonan11 lz
if not errorlevel 1 echo 结果: 没有答案
goto loop
原理说明:使用有理数进行计算,选择算式中最先结合的两数和它们之间的运算,并递归.
:liuzhaonan11
setlocal
set "f1=+"&set "f2=-"&set "f3=*"&set "f4=/"
for /l %%i in (1,1,!%1n!) do for /l %%j in (1,1,!%1n!) do if %%i neq %%j (
for /l %%k in (1,1,4) do (
setlocal
if %%k leq 2 set /a "z=%1%%jz*%1%%im!f%%k!%1%%jm*%1%%iz,m=%1%%jm*%1%%im"
if %%k equ 3 set /a "z=%1%%jz*%1%%iz,m=%1%%jm*%1%%im"
if %%k equ 4 set /a "z=%1%%jz*%1%%im,m=%1%%jm*%1%%iz"
if !%1n! equ 2 (
set /a "t=!z!-24*!m!"
if !t! equ 0 if !m! neq 0 echo 结果: !%1%%js! !f%%k! !%1%%is! = 24&exit /b 1
) else (
set "s=(!%1%%js! !f%%k! !%1%%is!)"&set /a "n=0"
for /l %%l in (1,1,!%1n!) do if %%l neq %%i if %%l neq %%j (
set /a "n+=1"&set "%1!n!z=!%1%%lz!"&set "%1!n!m=!%1%%lm!"&set "%1!n!s=!%1%%ls!"
)
set /a "n+=1"&set "%1!n!z=!z!"&set "%1!n!m=!m!"&set "%1!n!s=!s!"
set "%1n=!n!"&call%0 %1
if errorlevel 1 exit /b 1
)
endlocal
)
)
exit /b 0
作者:liuzhaonan11 2009-1-11 17:17
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |