批处理计算雯波那契数列
Posted on批处理计算雯波那契数列
批处理计算雯波那契数列
01
@
echo
off
02
rem 批处理计算雯波那契数列 03
setlocal enabledelayedexpansion
04
set
a=1 05
set
b=1
06
echo
任意键查看下一项. 07
echo
第1项为:!a!
08
echo
第2项为:!b! 09
:start
10
set
/a tn+=1 11
set
/a n_=!tn!+2
12
for
/l %%a
in
(1,1,1000)
do
( 13
set
ka=!a:~%%a,1!
14
if
not defined ka ( 15
set
la=%%a
16
goto :start_a 17
)
18
) 19
:start_a
20
for
/l %%a
in
(1,1,1000)
do
( 21
set
kb=!b:~%%a,1!
22
if
not defined kb ( 23
set
lb=%%a
24
goto :start_b 25
)
26
) 27
:start_b
28
if
!la! == !lb! ( 29
set
l=!la!
30
set
/a m=!a:~0,1!+!b:~0,1! 31
if
!m! geq 9 (
32
set
n=1 33
)
else
(
34
set
n=0 35
)
36
)
else
( 37
set
n=0
38
) 39
if
!la! gtr !lb! (
40
set
/a l=!la!+!n! 41
)
else
(
42
set
/a l=!lb!+!n! 43
)
44
for
/l %%a
in
(1,1,!l!)
do
( 45
if
!la! geq %%a (
46
set
x=!a:~-%%a,1! 47
)
else
(
48
set
x=0 49
)
50
if
!lb! geq %%a ( 51
set
y=!b:~-%%a,1!
52
)
else
( 53
set
y=0
54
) 55
if
defined o (
56
set
/a z=!x!+!y!+!o! 57
set
o=
58
)
else
( 59
set
/a z=!x!+!y!
60
) 61
if
!z! gtr 9
set
o=1
62
set
/p =!z:~-1,1!
set
/p all=<%temp%\temp.txt
64
65
)
66
for
/l %%a
in
(1,1,!l!)
do
set
/p =!all:~-%%a,1!
set
b=!a!
68
set
/p a=<%temp%\temp_.txt 69
del %temp%\temp/*.txt /q
70
if
"!a:~0,1!"
==
"0"
set
a=!a:~1! 71
echo
第!n_!项为:!a!
72
pause>nul 73
goto :start
来源: [http://my.oschina.net/veterans/blog/27841](http://my.oschina.net/veterans/blog/27841)