Cod sursa(job #780043)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 19 august 2012 18:44:53
Problema Nunta Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.03 kb
Program nunta;
type tip=array [1..300] of byte;
const max=300;
 var a,b,c:array [1..300] of byte;
     i,lim,m,k,n:integer;
     fi,fo:text;
procedure aduna(var a,b,c:tip);
 var t,s,j:integer;
begin
 t:=0; s:=0;
  for j:=max downto lim do begin
                          s:=a[j]+b[j]+t;
                           c[j]:=s mod 10;
                             t:=s div 10;
                                  end;
  if t<>0 then begin
               dec(lim);
                c[lim]:=t;
                end;
end;
begin
 assign(fi,'nunta.in');
  assign(fo,'nunta.out');
   reset(fi); rewrite(fo);
 readln(fi,n);
  a[max]:=1; b[max]:=1; lim:=max;
   repeat
    inc(m);
     if m mod 3=1 then aduna(a,b,c)
      else if m mod 3=2 then aduna(b,c,a)
                         else aduna(a,c,b);
    until m>=n-1;
  if n=1 then write(fo,'1') else
 if m mod 3=1 then for i:=lim to max do write(fo,c[i])
  else if m mod 3=2 then for i:=lim to max do write(fo,a[i])
   else for i:=lim to max do write(fo,b[i]);
  close(fo);
end.