
CODE: [Copy to clipboard]输入5个数字,如52559,则计算第5位+第(5+2)位+第(5+2+5)位+第(5+2+5+5)位+第(5+2+5+5+9)位的结果2 0 50000 50 0 20 4 1000 0 10 30 0 500 0 100 50000 2 0 1000 50 0 2 0 10 500 30 0 2 70 0 1000 100
CODE: [Copy to clipboard][ Last edited by zh159 on 2008-1-7 at 01:37 AM ]@echo off
set "Test=2 0 50000 50 0 20 4 1000 0 10 30 0 500 0 100 50000 2 0 1000 50 0 2 0 10 500 30 0 2 70 0 1000 100"
set/p input=input:
call :loop _ %Test%
echo -----
echo =%sss%
pause
exit
:loop
set n=0
:shiftloop
if "%1" == "" goto :eof
set/a n+=1
if %n% leq %input:~0,1% shift&&goto shiftloop
set/a sss=%sss%+%1
echo +%1
set "input=%input:~1%"
if not "%input%" == "" goto loop
goto :eof
| Quote: | |
|
CODE: [Copy to clipboard]@echo off
setlocal EnableDelayedExpansion
set/p input=input:
set "Test=2 0 50000 50 0 20 4 1000 0 10 30 0 500 0 100 50000 2 0 1000 50 0 2 0 10 500 30 0 2 70 0 1000 100"
:loop
set/a n=%input:~0,1%
set "input=%input:~1%"
for /f "tokens=%n%*" %%a in ("%Test%") do set/a sss+=%%a && echo +%%a && if not "%input%" =="" set test=%%b && goto loop
echo ------
echo =%sss%
:Eloop
set n=-1
for %%n in (zero one two three four five six seven eight nine ten) do (
set/a n+=1
if !n! == %sss:~0,1% (
set sss=%sss:~1%
set sssE=%sssE% %%n
)
)
if not "%sss%" == "" goto Eloop
echo =%sssE:~1%
pause
| Quote: | |
|
| Quote: | |
|
CODE: [Copy to clipboard]这个能解决长度的问题吧for /l %%i in (1,1,45) do call set "aaa=%%aaa%%%%i "
set /p in=input:
set /a 1/(in/10000),1/(100000/in)||goto :eof
set /a in1=%in:~0,1%,in2=in1+%in:~1,1%,in3=in2+%in:~2,1%,in4=in3+%in:~3,1%,in5=in4+%in:~4,1%
for %%i in (%aaa%) do set /a num+=1,1/^(num-in1^),1/^(num-in2^),1/^(num-in3^),1/^(num-in4^),1/^(num-in5^)||call set "output=%%output%%%%i "&&set /a out+=%%i
echo %out%=%output%
pause

| 欢迎光临 中国DOS联盟论坛 (http://cndos.fam.cx/forum/) | Powered by Discuz! 2.5 |