UVa OJ495-Fibonacci Freeze

    技术2024-04-16  8

     

    水题,高精:

    { Author:wzx961008 Problem:UVa 495-Fibonacci Freeze Verdict:Accepted Language:PASCAL Run Time:0.660s Submission Date:2011-01-27 15:59:00 } var f:array[0..5001]of ansistring; n:array[1..10000]of longint; i,t,max:longint; function HighPlus(s1,s2:ansistring):ansistring; var a,b,c:array[1..2000]of integer; lena,lenb,lenc,i,x:integer; begin HighPlus:=''; fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); fillchar(c,sizeof(c),0); lena:=length(s1); lenb:=length(s2); for i:=1 to lena do a[lena-i+1]:=ord(s1[i])-ord('0'); for i:=1 to lenb do b[lenb-i+1]:=ord(s2[i])-ord('0'); i:=1; x:=0; while (i<=lena)or(i<=lenb) do begin x:=a[i]+b[i]+x div 10; c[i]:=x mod 10; inc(i); end; if x>=10 then begin lenc:=i; c[i]:=1 end else lenc:=i-1; for i:=lenc downto 1 do HighPlus:=HighPlus+chr(c[i]+48); end; begin f[0]:='0'; f[1]:='1'; while not eof do begin inc(t); readln(n[t]); end; for i:=1 to t do if n[i]>max then max:=n[i]; for i:=2 to max do f[i]:=HighPlus(f[i-1],f[i-2]); for i:=1 to t do writeln('The Fibonacci number for ',n[i],' is ',f[n[i]]); end.  

    最新回复(0)