Cod sursa(job #152290)

Utilizator andumMorie Daniel Alexandru andum Data 9 martie 2008 12:22:12
Problema Nunta Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.84 kb
var n,i,q:longint;
    f,g:text;
    a,b,c:string;

function adun(x,y:string):string;
var i,t,max,q:integer;
    z:string;
begin
z:='';
max:=length(x);
if max<length(y) then max:=length(y);
if length(x)>length(y) then
   for i:=1 to length(x)-length(y) do y:='0'+y
                       else
   for i:=1 to length(y)-length(x) do x:='0'+x;
t:=0;
for i:=max downto 1 do begin
                       q:=t+ord(x[i])-48+ord(y[i])-48;
                       z:=chr((q mod 10)+48)+z;
                       q:=q div 10;
                       t:=q;
                       end;
if t<>0 then z:=chr(t+48)+z;
if z='' then z:='0';
adun:=z;
end;

{function scad(x,y:string):string;
var i,t,q:integer;
    z:string;
begin
z:='';
if length(x)>length(y) then
   for i:=1 to length(x)-length(y) do y:='0'+y;
for i:=length(x) downto 1 do begin
                             if x[i]<y[i] then begin
                                               t:=10;
                                               x[i-1]:=pred(x[i-1]);
                                               end
                                          else t:=0;
                             q:=t+ord(x[i])-48-(ord(y[i])-48);
                             z:=chr(q+48)+z;
                             end;
if z[1]='0' then delete(z,1,1);
if z='' then z:='0';
scad:=z;
end;}

begin
     assign(f,'nunta.in');
     assign(g,'nunta.out');
     reset(f);
     rewrite(g);
     readln(f,n);
     close(f);
     if n=1 then write(g,'1');
     if n=2 then write(g,'2');
     if n>2 then
        begin
         a:='1';
         b:='2';
         i:=2;
         while i<n do begin
                      inc(i);
                      c:=adun(a,b);
                      a:=b;
                      b:=c;
                      end;
         writeln(g,c);
        end;
close(g);
end.