Cod sursa(job #37989)

Utilizator runnaway90Oprescu Radu Constantin runnaway90 Data 25 martie 2007 13:13:32
Problema Next Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.88 kb
type vector=array[0..1000000]of longint;
function minim(a,b:longint):longint;
begin
if a>b then
   minim:=a
   else
       minim:=b;
end;
var c,a,b:vector;
        i,j,r,max:longint;
        p:char;
        nr:integer;
        f:text;
        ok:boolean;
begin
     c[0]:=1;
     c[1]:=0;
     assign(f,'next.in');
     reset(f);
              while not(eoln(f)) do
              begin
                   inc(i);
                   read(f,p);
                   val(p,a[i],nr);
              end;
              a[0]:=i;
              readln(f);
              while not(eoln(f)) do
              begin
                   inc(j);
                   read(f,p);
                   val(p,b[j],nr);
              end;
              b[0]:=j;
              for i:=1 to j div 2 do
              begin
                   b[i]:=b[i] xor b[j-i+1];
                   b[j-i+1]:=b[j-i+1]xor b[i];
                   b[i]:=b[i]xor b[j-i+1];
              end;
     close(f);
     ok:=true;
     while ok do
     begin
          ok:=false;
         max:=minim(c[0],b[0]);
         r:=0;
         for i:=1 to max do
         begin
          r:=c[i]+b[i]+r;
          c[i]:=r mod 10;
          r:=r div 10;
         end;
         c[0]:=max;
         if r>0 then
         begin
                c[0]:=c[0]+1;
                c[c[0]]:=1;
         end;
          if c[0]<a[0] then
             ok:=true
          else
          if c[0]=a[0] then
          begin
               for i:=1 to c[0] do
               if a[i]>c[c[0]-i+1] then
               begin
                  ok:=true;
                  break;
               end
               else
               if c[c[0]-i+1]>a[i] then
                  break;
          end;
     end;
     assign(f,'next.out');
     rewrite(f);
        for i:=c[0] downto 1 do
                write(f,c[i]);
     close(f);
end.