Cod sursa(job #37635)

Utilizator crawlerPuni Andrei Paul crawler Data 25 martie 2007 11:33:59
Problema Elimin 2 Scor 0
Compilator fpc Status done
Runda preONI 2007, Runda 4, Clasa a 10-a Marime 1.34 kb
type nr = 0..2046;
var a,b : array[0..2000] of char;
    x : array[0..2000,0..2000] of nr;
    y : array[0..2000,0..2000] of 0..3;
    i,j,n : word;
    cate : word;
    pus0 : boolean;
begin
 assign(input,'elimin2.in');reset(input);
 assign(output,'elimin2.out');rewrite(output);

 while(not eoln(input))do
  begin
   inc(n);
   read(a[n]);
  end;

 for i:=1 to n do
  b[i] := a[n-i+1];

 for i:=1 to n do
  for j:=1 to n do
   if(a[i] = b[j])then
    begin
     x[i][j] := 1 + x[i-1][j-1];
     y[i][j] := 3;
    end
     else
    begin
     if(x[i-1][j] > x[i][j-1])then
      begin
       x[i][j] := x[i-1][j];
       y[i][j] := 1;
      end
       else
      begin
       x[i][j] := x[i][j-1];
       y[i][j] := 2;
      end;
    end;

{
 for i:=0 to n do
  begin
   for j:=0 to n do
    write(x[i][j],' ');
   writeln;
  end;
}

 i := n;
 j := n;
 pus0 := false;

 while(i > 1)and(j > 1)do
  begin
   if(y[i][j] = 3)then
    begin
     if(pus0 = false)then
      if(ord(a[i]) > 48) then
       pus0 := true;

     if(pus0)then
      begin
       if(x[i][j] > cate)then
        write(a[i]);
      end
       else
      inc(cate);

     dec(i);
     dec(j);
    end
     else
    if(y[i][j] = 1)then
     dec(i)
      else
     dec(j);
  end;

 close(output);close(input);
end.