| 123456789101112131415161718192021222324252627282930313233343536 |
- const
- len1 = 13;
- len2 = 9;
- A :string = 'Super Ruez';
- B :string = 'dprtupzz';
- var
- i,j:byte;
- V : array[0..len2,0..len1] of byte;
- ret : string;
- begin
- Fillchar(V,len1*len2+2,0);
- V[1,1] := 0;
- if a[1]=b[1] then v[1,1]:=1;
- for i:=2 to len2 do if ((v[i-1,1]=1) or (a[1]=b[i])) then v[i,1] := 1
- else v[i,1]:=0;
- for j:=2 to len1 do if ((v[1,j-1]=1) or (a[j]=b[1])) then v[1,j] := 1
- else v[1,j]:=0;
- for i:=2 to len2 do
- for j:= 2 to len1 do
- begin
- if (a[j]=b[i]) then v[i,j];
- if v[i-1,j] > v[i,j-1] then v[i,j] := v[i-1,j]
- else v[i,j] := v[i,j-1];
- end;
- while v[i,j] <> 0 do
- begin
- if (v[i-1,j] = v[i,j]-1) and (v[i,j-1]=v[i,j]-1) then insert(a[j],ret,1);
- if v[i-1,j] > v[i,j-1] then dec(i) else dec(j);
- end;
- WriteLn('Max substring: ',ret);
- end.
|