Cod sursa(job #635611)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 19 noiembrie 2011 13:31:34
Problema PalM Scor 20
Compilator fpc Status done
Runda .com 2011 Marime 1.09 kb
Program palm;
 var a:array [0..500] of byte;
    ch:char;
     i,j,max,n:integer;
     fi,fo:text;
procedure control();
var x,y,nr:integer;
begin
 x:=j-1; y:=i+1; nr:=1;
 while (a[x]=a[y]) and (a[x]<=a[x+1]) and (x>=1) and (y<=n) do begin
                                        dec(x); inc(y); nr:=nr+2;
                                        end;
 if nr>max then max:=nr;
  i:=y-1;
end;
begin
 assign(fi,'palm.in');
  assign(fo,'palm.out');
 reset(fi); rewrite(fo);
  while not seekeoln(fi) do begin
                              inc(n);
                              read(fi,ch);
                              a[n]:=ord(ch);
                              end;
 for i:=1 to n do
  if (a[i-1]=a[i+1]) and (a[i-1]<=a[i]) then begin
                                              j:=i;
                                               control();
                                            end
   else if (a[i]=a[i-1]) then begin
                               j:=i-1;
                               control();
                                end;
 write(fo,max);
 close(fo);
end.