公共子串
Time Limit:1000MS Memory Limit:65536K Total Submit:196 Accepted:111
Time Limit:1000MS Memory Limit:65536K Total Submit:196 Accepted:111
Description
设有A、B两个字符串,找出A、B共同子串,每个字符串无相同字符,可以不连续,但顺序不能颠倒。
Input
第一行字符串A 第二行字符串B
Output
最长公共子串的长度.
Sample Input
abcfbc abfcabSample Output
4Source
elba
· Var· s1,s2:string;· i,j,best,p,q,r:longint;· a:array[0..300,0..300] of longint;· begin· read(s1); readln; read(s2);· for i:=1 to length(s1) do· for j:=1 to length(s2) do begin· if s1[i]=s2[j] then· begin· best:=0;p:=a[i-1,j-1]+1; q:=a[i,j-1];r:=a[i-1,j];if p>q thenbest:=pelse best:=q;if r>best thenbest:=r; a[i,j]:=best;end elsebeginbest:=0; p:=a[i,j-1]; q:=a[i-1,j]if p>q then best:=pelse best:=q; a[i,j]:=best; end; end; Writeln(a[length(s1),length(s2)]); end.
238

被折叠的 条评论
为什么被折叠?



