-
- @echo off
- echo 批处理计算雯波那契数列,按任意键查看下一个。
- setlocal enabledelayedexpansion
- set a=1
- set b=1
- echo 第1项为:!a!
- echo 第2项为:!b!
- :start
- set /a tn+=1
- set /a n_=!tn!+2
- for /l %%a in (1,1,1000) do (
- set ka=!a:~%%a,1!
- if not defined ka (
- set la=%%a
- goto :start_a
- )
- )
- :start_a
- for /l %%a in (1,1,1000) do (
- set kb=!b:~%%a,1!
- if not defined kb (
- set lb=%%a
- goto :start_b
- )
- )
- :start_b
- if !la! == !lb! (
- set l=!la!
- set /a m=!a:~0,1!+!b:~0,1!
- if !m! geq 9 (
- set n=1
- ) else (
- set n=0
- )
- ) else (
- set n=0
- )
- if !la! gtr !lb! (
- set /a l=!la!+!n!
- ) else (
- set /a l=!lb!+!n!
- )
- for /l %%a in (1,1,!l!) do (
- if !la! geq %%a (
- set x=!a:~-%%a,1!
- ) else (
- set x=0
- )
- if !lb! geq %%a (
- set y=!b:~-%%a,1!
- ) else (
- set y=0
- )
- if defined o (
- set /a z=!x!+!y!+!o!
- set o=
- ) else (
- set /a z=!x!+!y!
- )
- if !z! gtr 9 set o=1
- set /p =!z:~-1,1!<nul>>%temp%\temp.txt
- set /p all=<%temp%\temp.txt
- )
- for /l %%a in (1,1,!l!) do set /p =!all:~-%%a,1!<nul>>%temp%\temp_.txt
- set b=!a!
- set /p a=<%temp%\temp_.txt
- del %temp%\temp*.txt /q
- if "!a:~0,1!" == "0" set a=!a:~1!
- echo 第!n_!项为:!a!
- pause>nul
- goto :start
-
复制代码
[ 本帖最后由 lxzzr 于 2009-8-25 14:38 编辑 ] |