Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (42 sloc) 1.27 KB
@echo off
setlocal enableextensions enabledelayedexpansion
title 24点计算器
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:122121 lz
if not errorlevel 1 echo 结果: 没有答案
goto loop
:122121
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