『楼 主』:
用批处理算24点
因除运算有错,舍弃它了,但也能算出一部分,故权当娱乐而已,
修改输入同数出错
@echo off&setlocal enabledelayedexpansion
set/p a=输入第一个数:
set/p b=输入第二个数:
set/p c=输入第三个数:
set/p d=输入第四个数:
set m1=+&set m2=-&set m3=*
:a
set/a n+=1
for /l %%a in (1,1,3) do (
for /l %%b in (1,1,3) do (
for /l %%c in (1,1,3) do (
set/a str=a!m%%a!b!m%%b!c!m%%c!d
if "!str!" == "24" set/p=%a%!m%%a!%b%!m%%b!%c%!m%%c!%d%=!str!&exit
set/a str=^(a!m%%a!b^)!m%%b!c!m%%c!d
if "!str!" == "24" set/p=^(%a%!m%%a!%b%^)!m%%b!%c%!m%%c!%d%=!str!&exit
set/a str=a!m%%a!^(b!m%%b!c^)!m%%c!d
if "!str!" == "24" set/p=%a%!m%%a!^(%b%!m%%b!%c%^)!m%%c!%d%=!str!&exit
set/a str=a!m%%a!b!m%%b!^(c!m%%c!d^)
if "!str!" == "24" set/p=%a%!m%%a!%b%!m%%b!^(%c%!m%%c!%d%^)=!str!&exit
set/a str=^(a!m%%a!b!m%%b!c^)!m%%c!d
if "!str!" == "24" set/p=^(%a%!m%%a!%b%!m%%b!%c%^)!m%%c!%d%=!str!&exit
set/a str=a!m%%a!^(b!m%%b!c!m%%c!d^)
if "!str!" == "24" set/p=%a%!m%%a!^(%b%!m%%b!%c%!m%%c!%d%^)=!str!&exit
set/a str=^(a!m%%a!b^)!m%%b!^(c!m%%c!d^)
if "!str!" == "24" set/p=^(%a%!m%%a!%b%^)!m%%b!^(%c%!m%%c!%d%^)=!str!&exit
set/a str=^(a!m%%a!^(b!m%%b!c^)^)!m%%c!d
if "!str!" == "24" set/p=^(%a%!m%%a!^(%b%!m%%b!%c%^)^)!m%%c!%d%=!str!&exit
set/a str=^(^(a!m%%a!b^)!m%%b!c^)!m%%c!d
if "!str!" == "24" set/p=^(^(%a%!m%%a!%b%^)!m%%b!%c%^)!m%%c!%d%=!str!&exit
set/a str=a!m%%a!^(b!m%%b!^(c!m%%c!d^)^)
if "!str!" == "24" set/p=%a%!m%%a!^(%b%!m%%b!^(%c%!m%%c!%d%^)^)=!str!&exit
set/a str=a!m%%a!^(^(b!m%%b!c^)!m%%c!d^)
if "!str!" == "24" set/p=%a%!m%%a!^(^(%b%!m%%b!%c%^)!m%%c!%d%^)=!str!&exit
)
)
)
if !n! lss 4 set/a a=%b%,b=%c%,c=%d%,d=%a%&goto a
if !n! lss 5 set/a a=%b%,b=%c%,c=%a%,d=%d%&goto a
if !n! lss 8 set/a a=%b%,b=%c%,c=%d%,d=%a%&goto a
if !n! lss 9 set/a a=%d%,b=%a%,c=%c%,d=%b%&goto a
if !n! lss 12 set/a a=%b%,b=%c%,c=%d%,d=%a%&goto a
if !n! lss 13 set/a a=%a%,b=%b%,c=%d%,d=%c%&goto a
if !n! lss 16 set/a a=%b%,b=%c%,c=%d%,d=%a%&goto a
if !n! lss 17 set/a a=%b%,b=%a%,c=%c%,d=%d%&goto a
if !n! lss 20 set/a a=%b%,b=%c%,c=%d%,d=%a%&goto a
if !n! lss 21 set/a a=%b%,b=%c%,c=%a%,d=%d%&goto a
if !n! lss 24 set/a a=%b%,b=%c%,c=%d%,d=%a%&goto a
echo.
echo 对不起,没算出来!
echo.
pause
@echo off&setlocal enabledelayedexpansion
set/p var=输入4个数(空格隔开)
for %%i in (!var!) do set/a n+=1&set !n!=%%i
set m1=+&set m2=-&set m3=*
for /l %%i in (1 1 %n%) do (
for /l %%j in (1 1 %n%) do (
for /l %%k in (1 1 %n%) do (
for /l %%l in (1 1 %n%) do (
if not "%%i"=="%%j" (
if not "%%i"=="%%k" (
if not "%%i"=="%%l" (
if not "%%j"=="%%k" (
if not "%%j"=="%%l" (
if not "%%l"=="%%k" (
if not defined %%i%%j%%k%%l set %%i%%j%%k%%l=ok&(
for /l %%a in (1,1,3) do (
for /l %%b in (1,1,3) do (
for /l %%c in (1,1,3) do (
set/a str=!%%i!!m%%a!!%%j!!m%%b!!%%k!!m%%c!!%%l!
if "!str!" == "24" set/p=!%%i!!m%%a!!%%j!!m%%b!!%%k!!m%%c!!%%l!=!str!&exit
set/a str=^(!%%i!!m%%a!!%%j!^)!m%%b!!%%k!!m%%c!!%%l!
if "!str!" == "24" set/p=^(!%%i!!m%%a!!%%j!^)!m%%b!!%%k!!m%%c!!%%l!=!str!&exit
set/a str=!%%i!!m%%a!^(!%%j!!m%%b!!%%k!^)!m%%c!!%%l!
if "!str!" == "24" set/p=!%%i!!m%%a!^(!%%j!!m%%b!!%%k!^)!m%%c!!%%l!=!str!&exit
set/a str=!%%i!!m%%a!!%%j!!m%%b!^(!%%k!!m%%c!!%%l!^)
if "!str!" == "24" set/p=!%%i!!m%%a!!%%j!!m%%b!^(!%%k!!m%%c!!%%l!^)=!str!&exit
set/a str=^(!%%i!!m%%a!!%%j!!m%%b!!%%k!^)!m%%c!!%%l!
if "!str!" == "24" set/p=^(!%%i!!m%%a!!%%j!!m%%b!!%%k!^)!m%%c!!%%l!=!str!&exit
set/a str=!%%i!!m%%a!^(!%%j!!m%%b!!%%k!!m%%c!!%%l!^)
if "!str!" == "24" set/p=!%%i!!m%%a!^(!%%j!!m%%b!!%%k!!m%%c!!%%l!^)=!str!&exit
set/a str=^(!%%i!!m%%a!!%%j!^)!m%%b!^(!%%k!!m%%c!!%%l!^)
if "!str!" == "24" set/p=^(!%%i!!m%%a!!%%j!^)!m%%b!^(!%%k!!m%%c!!%%l!^)=!str!&exit
set/a str=^(!%%i!!m%%a!^(!%%j!!m%%b!!%%k!^)^)!m%%c!!%%l!
if "!str!" == "24" set/p=^(!%%i!!m%%a!^(!%%j!!m%%b!!%%k!^)^)!m%%c!!%%l!=!str!&exit
set/a str=^(^(!%%i!!m%%a!!%%j!^)!m%%b!!%%k!^)!m%%c!!%%l!
if "!str!" == "24" set/p=^(^(!%%i!!m%%a!!%%j!^)!m%%b!!%%k!^)!m%%c!!%%l!=!str!&exit
set/a str=!%%i!!m%%a!^(!%%j!!m%%b!^(!%%k!!m%%c!!%%l!^)^)
if "!str!" == "24" set/p=!%%i!!m%%a!^(!%%j!!m%%b!^(!%%k!!m%%c!!%%l!^)^)=!str!&exit
set/a str=!%%i!!m%%a!^(^(!%%j!!m%%b!!%%k!^)!m%%c!!%%l!^)
if "!str!" == "24" set/p=!%%i!!m%%a!^(^(!%%j!!m%%b!!%%k!^)!m%%c!!%%l!^)=!str!&exit
))))))))))))))
echo.
echo 对不起,没算出来!
echo.
pause [ Last edited by terse on 2008-7-6 at 11:12 PM ]
|