Pagini recente » Cod sursa (job #264233) | Cod sursa (job #1451615) | Cod sursa (job #3206144) | Cod sursa (job #2695433) | Cod sursa (job #37871)
Cod sursa(job #37871)
type nr = 0..2045;
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))and(not eof(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;
if(x[n][n] = 1)then
begin
for i:=1 to n do
if(ord(a[i]) > 48)then
begin
write(a[i]);
break;
end;
end
else
while(i > 0)and(j > 0)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
if(y[i][j] = 2)then
dec(j);
end;
writeln;
close(output);close(input);
end.