a,b,ls1,ls2,out:ansistring;
l1,l2,ml:integer;
f:array[1..1000,1..1000] of integer;
fa:array[1..1000] of integer;
i,j,k:integer;
procedure try;
begin
for j:=1 to l2-i+1 do
if j>ml then
begin
ls1:=copy(a,i,j);
for k:=1 to l2-j+1 do
begin
ls2:=copy(b,k,j);
if (ls1=ls2) and (j>ml) then
begin
ml:=j;
out:=ls1;
end;
end;
if ls1<>out then exit;
end;
end;
begin
readln(a);
readln(b);
l1:=length(a);
l2:=length(b);
for i:=1 to l1 do try;
writeln(out);
end.
==================================================
状态题目:最长公共子串
状态编号: [查看该题]
状态: Accepted
测评机: Xeost[5]
得分: 100分
提交日期: 2008-7-26 23:47:00
有效耗时: 该状态没有记录
测试结果1: 测试结果正确
测试结果2: 测试结果正确
测试结果3: 测试结果正确
测试结果4: 测试结果正确
测试结果5: 测试结果正确
测试结果6: 测试结果正确
测试结果7: 测试结果正确
测试结果8: 测试结果正确
测试结果9: 测试结果正确
测试结果10: 测试结果正确
program zcggzc;
var
i,j,k,m,p,maxlen,start,js:longint;
stra,strb:ansistring;
procedure init;
begin
readln(stra);
readln(strb);
maxlen:=0; i:=0;
k:=length(stra);
end;
begin
init;
for i:=1 to k do
begin
for j:=1 to k do
begin
if strb[j]=stra[i] then
begin
m:=0;
js:=0;
for p:=j to k do
begin
inc(js);
if stra[i+js-1]=strb[p] then inc(m)
else
begin
if m>maxlen then begin start:=j; maxlen:=m; break; end;
break;
end;
if p=k then if m>maxlen then begin start:=j; maxlen:=m; break; end;
end;
end;
end;
end;
writeln(copy(strb,start,maxlen));
end.
var a,b,c,max:ansistring;
i,j:longint;
begin
readln(a);readln(b);
for i:=1 to length(a) do begin
for j:=i to length(a) do begin
c:=copy(a,i,j-i+1);
if (pos(c,b)<>0)and(length(c)>length(max))then max:=c;
end;
end;
writeln(max);
end.
var
st1,st2,st,str:ansistring;
l,n,max,i,j,k:longint;
begin
readln(st1);
readln(st2);
l:=length(st1);
max:=0;
for i:=1 to l do begin
st:='';
for j:=i to l do begin
st:=st+st1[j];
n:=pos(st,st2);
if n<>0 then k:=length(st);
if k>max then begin
max:=k;
str:=st;
end;
end;
end;
writeln(str);
readln;
end.