29 lines
733 B
Text
29 lines
733 B
Text
$ include "seed7_05.s7i";
|
|
|
|
const func string: lcs (in string: a, in string: b) is func
|
|
result
|
|
var string: lcs is "";
|
|
local
|
|
var string: x is "";
|
|
var string: y is "";
|
|
begin
|
|
if a <> "" and b <> "" then
|
|
if a[length(a)] = b[length(b)] then
|
|
lcs := lcs(a[.. pred(length(a))], b[.. pred(length(b))]) & str(a[length(a)]);
|
|
else
|
|
x := lcs(a, b[.. pred(length(b))]);
|
|
y := lcs(a[.. pred(length(a))], b);
|
|
if length(x) > length(y) then
|
|
lcs := x;
|
|
else
|
|
lcs := y;
|
|
end if;
|
|
end if;
|
|
end if;
|
|
end func;
|
|
|
|
const proc: main is func
|
|
begin
|
|
writeln(lcs("thisisatest", "testing123testing"));
|
|
writeln(lcs("1234", "1224533324"));
|
|
end func;
|