Ocena użytkownikóww: ***** / 1
Nadesłany przez Tomasz Lubiński, 18 stycznia 2007 01:00
Kod przedstawiony poniżej przedstawia główną część rozwiązania problemu.
Pobierz pełne rozwiązanie.Jeżeli nie odpowiada Ci sposób formatowania kodu przez autora skorzystaj z pretty printer'a i dostosuj go automatycznie do siebie.
podtekst.adb:
-- Najdluzsze wspolne podslowo
-- www.algorytm.org
-- (c)2007 Tomasz Lubinski
with Text_IO;
use Text_IO;
procedure podtekst is
subtype string_type is String(1..100);
type int_array is array(1..100) of Integer;
type int_arraay2 is array(1..100) of int_array;
m:Integer;
n:Integer;
maxi:Integer:=0;
ind:Integer:=0;
s1: string_type;
s2: string_type;
a: int_arraay2;
begin
Put_Line("Podaj pierwszy ciag");
Get_Line(s1, m);
Put_Line("Podaj drugi ciag");
Get_Line(s2, n);
for i in 1 .. 100 loop
a(1)(i) := 0;
a(i)(1) := 0;
end loop;
for i in 2 .. m+1 loop
for j in 2 .. n+1 loop
if s1(i-1) /= s2(j-1) then
a(i)(j) := 0;
else
a(i)(j) := a(i-1)(j-1) + 1;
if a(i)(j) > maxi then
maxi := a(i)(j);
ind := i;
end if;
end if;
end loop;
end loop;
Put_Line("Najdluzszy wspolny podciag ma dlugosc " & Integer'Image(maxi));
if maxi /= 0 then
Put_Line("Jest to:");
for i in 1..maxi loop
Put(s1(ind+i-1-maxi) & "");
end loop;
end if;
end;