复制代码
- @echo off
- setlocal enabledelayedexpansion
- title 算24
- set suan=24
- set cg=0
- set /p suan=输入要算的数字:
- set /p y=输入第一个数:
- set /p e=输入第二个数:
- set /p s=输入第三个数:
- set /p f=输入第四个数:
- cls
- echo 正在计算,请稍候...
- set a=%y%
- set b=%e%
- set c=%s%
- set d=%f%
- call 1.cmd
- set a=%y%
- set b=%e%
- set d=%s%
- set c=%f%
- call 1.cmd
- set a=%y%
- set c=%e%
- set b=%s%
- set d=%f%
- call 1.cmd
- set a=%y%
- set c=%e%
- set d=%s%
- set b=%f%
- call 1.cmd
- set a=%y%
- set d=%e%
- set b=%s%
- set c=%f%
- call 1.cmd
- set a=%y%
- set d=%e%
- set c=%s%
- set b=%f%
- call 1.cmd
- set b=%y%
- set a=%e%
- set c=%s%
- set d=%f%
- call 1.cmd
- set b=%y%
- set a=%e%
- set d=%s%
- set c=%f%
- call 1.cmd
- set b=%y%
- set c=%e%
- set a=%s%
- set d=%f%
- call 1.cmd
- set b=%y%
- set c=%e%
- set d=%s%
- set a=%f%
- call 1.cmd
- set b=%y%
- set c=%e%
- set d=%s%
- set a=%f%
- call 1.cmd
- set b=%y%
- set d=%e%
- set a=%s%
- set c=%f%
- call 1.cmd
- set b=%y%
- set d=%e%
- set c=%s%
- set a=%f%
- call 1.cmd
- set c=%y%
- set a=%e%
- set b=%s%
- set d=%f%
- call 1.cmd
- set c=%y%
- set a=%e%
- set d=%s%
- set b=%f%
- call 1.cmd
- set c=%y%
- set b=%e%
- set a=%s%
- set d=%f%
- call 1.cmd
- set c=%y%
- set b=%e%
- set d=%s%
- set a=%f%
- call 1.cmd
- set c=%y%
- set d=%e%
- set a=%s%
- set b=%f%
- call 1.cmd
- set c=%y%
- set d=%e%
- set b=%s%
- set a=%f%
- call 1.cmd
- set d=%y%
- set a=%e%
- set b=%s%
- set c=%f%
- call 1.cmd
- set d=%y%
- set a=%e%
- set c=%s%
- set b=%f%
- call 1.cmd
- set d=%y%
- set b=%e%
- set a=%s%
- set c=%f%
- call 1.cmd
- set d=%y%
- set b=%e%
- set c=%s%
- set a=%f%
- call 1.cmd
- set d=%y%
- set c=%e%
- set a=%s%
- set b=%f%
- call 1.cmd
- set d=%y%
- set c=%e%
- set b=%s%
- set a=%f%
- call 1.cmd
- if %cg%==0 echo 对不起,没算出来,按任意键退出...
- if %cg%==1 echo 计算完毕,所有结果都已显示,按任意键退出...
- pause>>%tmp%\pause.tmp
复制代码
- set /a js=((%a%+%b%)+%c%)+%d%
- if %js%==%suan% echo ((%a%+%b%)+%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)+%c%)-%d%
- if %js%==%suan% echo ((%a%+%b%)+%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)+%c%)*%d%
- if %js%==%suan% echo ((%a%+%b%)+%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)+%c%)/%d%
- if %js%==%suan% echo ((%a%+%b%)+%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)-%c%)+%d%
- if %js%==%suan% echo ((%a%+%b%)-%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)-%c%)-%d%
- if %js%==%suan% echo ((%a%+%b%)-%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)-%c%)*%d%
- if %js%==%suan% echo ((%a%+%b%)-%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)-%c%)/%d%
- if %js%==%suan% echo ((%a%+%b%)-%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)*%c%)+%d%
- if %js%==%suan% echo ((%a%+%b%)×%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)*%c%)-%d%
- if %js%==%suan% echo ((%a%+%b%)×%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)*%c%)*%d%
- if %js%==%suan% echo ((%a%+%b%)×%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)*%c%)/%d%
- if %js%==%suan% echo ((%a%+%b%)×%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)/%c%)+%d%
- if %js%==%suan% echo ((%a%+%b%)÷%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)/%c%)-%d%
- if %js%==%suan% echo ((%a%+%b%)÷%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)/%c%)*%d%
- if %js%==%suan% echo ((%a%+%b%)÷%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%+%b%)/%c%)/%d%
- if %js%==%suan% echo ((%a%+%b%)÷%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)+%c%)+%d%
- if %js%==%suan% echo ((%a%-%b%)+%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)+%c%)-%d%
- if %js%==%suan% echo ((%a%-%b%)+%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)+%c%)*%d%
- if %js%==%suan% echo ((%a%-%b%)+%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)+%c%)/%d%
- if %js%==%suan% echo ((%a%-%b%)+%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)-%c%)+%d%
- if %js%==%suan% echo ((%a%-%b%)-%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)-%c%)-%d%
- if %js%==%suan% echo ((%a%-%b%)-%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)-%c%)*%d%
- if %js%==%suan% echo ((%a%-%b%)-%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)-%c%)/%d%
- if %js%==%suan% echo ((%a%-%b%)-%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)*%c%)+%d%
- if %js%==%suan% echo ((%a%-%b%)×%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)*%c%)-%d%
- if %js%==%suan% echo ((%a%-%b%)×%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)*%c%)*%d%
- if %js%==%suan% echo ((%a%-%b%)×%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)*%c%)/%d%
- if %js%==%suan% echo ((%a%-%b%)×%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)/%c%)+%d%
- if %js%==%suan% echo ((%a%-%b%)÷%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)/%c%)-%d%
- if %js%==%suan% echo ((%a%-%b%)÷%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)/%c%)*%d%
- if %js%==%suan% echo ((%a%-%b%)÷%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%-%b%)/%c%)/%d%
- if %js%==%suan% echo ((%a%-%b%)÷%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)+%c%)+%d%
- if %js%==%suan% echo ((%a%×%b%)+%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)+%c%)-%d%
- if %js%==%suan% echo ((%a%×%b%)+%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)+%c%)*%d%
- if %js%==%suan% echo ((%a%×%b%)+%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)+%c%)/%d%
- if %js%==%suan% echo ((%a%×%b%)+%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)-%c%)+%d%
- if %js%==%suan% echo ((%a%×%b%)-%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)-%c%)-%d%
- if %js%==%suan% echo ((%a%×%b%)-%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)-%c%)*%d%
- if %js%==%suan% echo ((%a%×%b%)-%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)-%c%)/%d%
- if %js%==%suan% echo ((%a%×%b%)-%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)*%c%)+%d%
- if %js%==%suan% echo ((%a%×%b%)×%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)*%c%)-%d%
- if %js%==%suan% echo ((%a%×%b%)×%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)*%c%)*%d%
- if %js%==%suan% echo ((%a%×%b%)×%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)*%c%)/%d%
- if %js%==%suan% echo ((%a%×%b%)×%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)/%c%)+%d%
- if %js%==%suan% echo ((%a%×%b%)÷%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)/%c%)-%d%
- if %js%==%suan% echo ((%a%×%b%)÷%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)/%c%)*%d%
- if %js%==%suan% echo ((%a%×%b%)÷%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%*%b%)/%c%)/%d%
- if %js%==%suan% echo ((%a%×%b%)÷%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)+%c%)+%d%
- if %js%==%suan% echo ((%a%÷%b%)+%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)+%c%)-%d%
- if %js%==%suan% echo ((%a%÷%b%)+%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)+%c%)*%d%
- if %js%==%suan% echo ((%a%÷%b%)+%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)+%c%)/%d%
- if %js%==%suan% echo ((%a%÷%b%)+%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)-%c%)+%d%
- if %js%==%suan% echo ((%a%÷%b%)-%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)-%c%)-%d%
- if %js%==%suan% echo ((%a%÷%b%)-%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)-%c%)*%d%
- if %js%==%suan% echo ((%a%÷%b%)-%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)-%c%)/%d%
- if %js%==%suan% echo ((%a%÷%b%)-%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)*%c%)+%d%
- if %js%==%suan% echo ((%a%÷%b%)×%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)*%c%)-%d%
- if %js%==%suan% echo ((%a%÷%b%)×%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)*%c%)*%d%
- if %js%==%suan% echo ((%a%÷%b%)×%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)*%c%)/%d%
- if %js%==%suan% echo ((%a%÷%b%)×%c%)÷%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)/%c%)+%d%
- if %js%==%suan% echo ((%a%÷%b%)÷%c%)+%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)/%c%)-%d%
- if %js%==%suan% echo ((%a%÷%b%)÷%c%)-%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)/%c%)*%d%
- if %js%==%suan% echo ((%a%÷%b%)÷%c%)×%d%=%suan%&set cg=1
- set /a js=((%a%/%b%)/%c%)/%d%
- if %js%==%suan% echo ((%a%÷%b%)÷%c%)÷%d%=%suan%&set cg=1
复制代码
- @echo off&color c0&title 算24
- setlocal ENABLEDELAYEDEXPANSION
- ::from 771815005
- :number1
- set /a shu1=%random%%%11
- if "%shu1%"=="0" goto number1
- :number2
- set /a shu2=%random%%%11
- for %%b in (%shu1% 0) DO if %shu2%==%%b goto number2
- :number3
- set /a shu3=%random%%%11
- for %%j in (%shu1% %shu2% 0) DO if %shu3%==%%j goto number3
- :number4
- set /a shu4=%random%%%11
- for %%h in (%shu1% %shu2% %shu3% 0) DO if %shu4%==%%h goto number4
- echo.&echo 请用%shu1% %shu2% %shu3% %shu4%算出24。
- echo.&echo S键跳过,E键退出。
- :input
- Echo.&Set /p suan=请输入算式:&cls&echo.
- echo 验证中,请稍候...&echo.
- if "%suan%"=="" goto input
- if %suan%==s cls&goto number1
- if %suan%==e cls&echo.&Echo goodbye!&pause>nul&exit
- set suan=%suan:[=(%
- set suan=%suan:]=)%
- set /a jieguo="%suan%"&set tp=0
- for /l %%i in (1 1 4) do (
- echo "%suan%"|find "+!shu%%i!">nul||echo "%suan%"|find "-!shu%%i!">nul||^
- echo "%suan%"|find "*!shu%%i!">nul||echo "%suan%"|find "/!shu%%i!">nul||^
- echo "%suan%"|find "(!shu%%i!">nul||set /a tp+=1
- )
- if not "%suan:~0,1%"=="(" set /a tp-=1
- if %jieguo% equ 24 if %tp% lss 1 goto yes
- :no
- echo 啊,不对!&goto next
- :yes
- echo Yes,对了!
- :next
- echo.&echo 下一题...
- pause>nul&cls&goto number1
本版规则
1、求代码、寻求代码解释、探讨代码得失的帖子均可发在本版块,其余话题禁止在本版讨论;
2、求助时,务必在顶楼一次性把问题交代清楚;若文字难以表述,请配图说明,或是上传附件;但是,一切操作应从节约论坛资源的角度出发,能文字说明清楚的就无需再发图片,小图能说明问题的尽量不截全图,在不影响效果的前提下尽量压缩图片及附件;
3、所发代码若不止一行,请务必用code标签把代码部分首尾括起来,以便他人复制;
复制代码
- @echo off&
- setlocal enabledelayedexpansion
- set/p str=输入4个数(空格隔开)
- for %%i in (!str!) do set/a n+=1&set var=!var! !n!&set "!n!=%%i"
- set m1=+&set m2=-&set m3=*
- for %%i in (!var!) do (
- set "var1=!var:%%i=!"
- for %%j in (!var1!) do (
- set "var2=!var1:%%j=!"
- for %%k in (!var2!) do (
- set "var3=!var2:%%k=!"
- for %%l in (!var3!) do (
- 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! equ 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! equ 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! equ 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! equ 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! equ 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! equ 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! equ 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! equ 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! equ 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! equ 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! equ 24 set/p=!%%i!!m%%a!^(^(!%%j!!m%%b!!%%k!^)!m%%c!!%%l!^)=!str!&exit
- )))))))
- echo.
- echo 对不起,没算出来!
- echo.
- pause&exit
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |