公共子串 Time Limit:1000MS Memory Limit:65536K Total Submit:203 Accepted:117
Description 设有A、B两个字符串,找出A、B共同子串,每个字符串无相同字符,可以不连续,但顺序不能颠倒。
Input 第一行字符串A 第二行字符串B
Output 最长公共子串的长度.
Sample Input abcfbc abfcab
Sample Output 4
var
s,s1:
string;
i,j:longint;
f:
array [
0..
111,
0..
111]
of longint;
begin
readln(s);
readln(s1);
for i:=
1 to length(s)
do
for j:=
1 to length(s1)
do
if s[i]=s1[j]
then f[i,j]:=f[i-
1,j-
1]+
1
else if f[i-
1,j]>f[i,j-
1]
then f[i,j]:=f[i-
1,j]
else f[i,j]:=f[i,j-
1];
writeln(f[i,j]);
end.
转载请注明原文地址: https://ju.6miu.com/read-24681.html