楼上tireless给出的动态演示中的结果好像有问题吧。第一个还正确,后两个都不对啊。
现在就好了,刚才没看清楚规则,全部完后还要相加。已经更新
- @echo off&setlocal enabledelayedexpansion 2>nul
- mode con lines=15 cols=20
- set "code=32 31 29 28 26 25 24 22 20 19 17 16 15 13 11 10 58 7 6 4 3 1"
- set "money=100 1000 70 2 30 500 10 2 50 1000 2 50000 100 500 30 10 1000 4 20 50 50000 2"
- for %%i in (!code!) do (
- for /f "tokens=1" %%j in ("!money!") do set m%%i=%%j
- set money=!money:* =!
- )
- :begin
- cls
- set number_by_hand=
- set str=
- echo.
- set /p "str=请输入:"
- if not %str% geq 11111 echo.&echo 输入有误。&pause>nul&goto :begin
- if not %str% leq 99999 echo.&echo 输入有误。&pause>nul&goto :begin
- for /l %%i in (0 1 4) do (
- set "number_by_hand=!number_by_hand!!str:~%%i,1! "
- )
- set /a sum=0,num=0
- for %%i in (!number_by_hand!) do (
- set /a num+=1
- set /a sum+=%%i
- set t!num!=!sum!
- )
- set "number=!t1! !t2! !t3! !t4! !t5!"
- if not !t5! leq 32 echo.&echo 5个数字和超过32。&pause>nul&goto :begin
- set flag=0
- set result=0
- for %%i in (!number!) do (
- for %%j in (!code!) do (
- if %%i equ %%j (
- set /a result+=!m%%j!
- set flag=1
- )
- )
- )
- if !flag! equ 1 (echo.&echo 中奖金额为:!result!&echo.) else (echo.&echo 谢谢惠顾!!&echo.)
- pause>nul
- goto :begin
复制代码
以上代码稍微改下,就可以生成一系列指定中奖金额的5位数,或者不中奖的5位数。
[ 本帖最后由 lhjoanna 于 2008-12-8 03:02 编辑 ] |