联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
::code by wxcute @ bathome @echo off title 三八二十四 mode con cols=56 lines=7 cd/d "%~dp0" ::临时文件→ echo j+^ i-^ c*^ h/>TMP_fh if not #%1==# %0 ::思路 ::%4 %_1% %5 %_2% %6 %_3% %7 :: A + B + C + D ::ABCD做排列 ::符号做循环,并用以下公式加括号 echo %%4%%_1%%%%5%%_2%%%%6%%_3%%%%7^ (%%4%%_1%%%%5)%%_2%%%%6%%_3%%%%7^ (%%4%%_1%%%%5%%_2%%%%6)%%_3%%%%7^ %%4%%_1%%(%%5%%_2%%%%6)%%_3%%%%7^ %%4%%_1%%(%%5%%_2%%%%6%%_3%%%%7)^ %%4%%_1%%%%5%%_2%%(%%6%%_3%%%%7)^ (%%4%%_1%%%%5)%%_2%%(%%6%%_3%%%%7)>TMP_gs ::←临时文件 :bg endlocal cls setlocal enabledelayedexpansion set sr1=a b c d ::输入或生成四个1-10的数→ echo 直接回车将随机生成4个数 set/p shuru=输入四个1-10的数(用空格空开): if "%shuru%"=="exit" del/q TMP_fh TMP_gs&goto :eof if "%shuru%"=="" ( set sw=随机&for %%s in (%sr1%) do call :setR %%s ) else ( echo !shuru: =!|findstr "[^0-9]">nul&&goto err for %%r in (%shuru%) do call :setS %%r num for /l %%f in (1 1 4) do ( if not defined num%%f goto :err if !num%%f! lss 1 goto :err if !num%%f! gtr 10 goto :err ) set/a a=!num1!,b=!num2!,c=!num3!,d=!num4! set sw=输入 ) cls echo. echo. echo 四个%sw%数:%a% %b% %c% %d% ::← set/p= 正在计算,请稍后...<nul ::排列→ for %%a in (!sr1!) do (set sr2=!sr1:%%a =! for %%b in (!sr2!) do (set sr3=!sr2:%%b =! for %%c in (!sr3!) do (set sr4=!sr3:%%c =! call :pl %%a %%b %%c !sr4! if defined flag goto :show ) ) ) ::←排列 :show if defined flag ( set/p= <nul echo. ::运算符号替换→ for /f "tokens=1-4 delims=*" %%c in ("!gs!") do set gs_=%%c×%%d×%%e×%%f set/a xn=_c-3 call set gs_=%%gs_:~,!xn!%% set gs=!gs_:+=+! set gs=!gs:-=-! set gs=!gs:/=÷! ::←运算符号替换 set/p= 其中一结果:!gs!=%jg%<nul ) else ( set/p= <nul echo. set/p= 不好意思,没有算出来=_=^|<nul ) pause>nul goto :bg ::调用标签→ :pl call :fh !%1! !%2! !%3! !%4! goto :eof ::符号循环→ :fh set/a _j=0,_i=0,_c=0,_h=0 for /f %%i in (TMP_fh) do ( for /f %%j in (TMP_fh) do ( for /f %%k in (TMP_fh) do ( call :crfh %%i %%j %%k %1 %2 %3 %4 if defined flag goto :eof ) ) ) goto :eof ::←符号循环 :crfh set fh1=%1&set fh2=%2&set fh3=%3 set _1=!fh1:~-1!&set _2=!fh2:~-1!&set _3=!fh3:~-1! set/a _!fh1:~,1!+=1,_!fh2:~,1!+=1,_!fh3:~,1!+=1 set/a he=_j+_i+_c+_h ::七个公式→ for /f %%g in (TMP_gs) do ( call :isR "%%g" %4 %5 %6 %7 if defined flag goto :eof ) if !he! equ 3 set/a _j=0,_i=0,_c=0,_h=0 goto :eof ::←七个公式 ::判断24整除→ :isR if %_i% equ 3 goto :eof if %_h% equ 3 goto :eof set gs=%~1 set/a jg=%gs% 2>nul if "%jg%"=="24" ( set flag=1 if %_h% equ 1 ( if not "%gs:(=%"=="%gs%" ( if "%gs:/(=%"=="%gs%" ( if "%gs:)/=%"=="%gs%" ( call :gh0 %2 %3 %4 %5 ) else call :ch1 gs gs2 ) else call :ch1 gs gs2 ) else call :gh0 %2 %3 %4 %5 ) else if %_h% equ 2 call :ch2 gs gs2 ) goto :eof :gh0 if %_3%==/ set/a mod=%3%%%4&if not !mod!#==0# set flag=&goto :eof if %_2%==/ set/a mod=%2%%%3&if not !mod!#==0# set flag=&goto :eof if %_1%==/ set/a mod=%1%%%2&if not !mod!#==0# set flag=&goto :eof goto :eof :ch1 set "%2=!%1:/=%%!" set/a gs2=%gs2% 2>nul if not #%gs2%==#0 set flag= goto :eof :ch2 set "%11=!%1:(=!" if not "%gs1%"=="%gs%" set flag=&goto :eof set "%2=!%1:/1=!" set "gs2=!gs2:/=%%!" set/a gs2=%gs2% 2>nul if not #%gs2% equ #0 set flag= goto :eof :setR set/a %1=%random%%%10+1 goto :eof :setS set/a %2+=1 set num%num%=%1 goto :eof :err echo 输入有误!请重新输入 ping -n 2 127.1>nul goto :bg ::←判断整除
附件 1: 三八二十四.rar (2008-10-10 21:19, 1.67 K,下载次数: 11)
四个输入数:2 3 4 1 其中一结果:+=+=24
四个输入数:1 2 3 4 其中一结果:(1+2+3)×4=24