Exkmp

来源:互联网 发布:淘宝有哪些孕妇装店 编辑:程序博客网 时间:2024/06/05 06:34
var        extand,next:array[0..100000] of longint;        s,s1:ansistring;        l,l1,n,m,i,j,p,a:longint;begin        readln(s);        readln(s1);        l:=length(s);        l1:=length(s1);        j:=-1;        p:=0;        a:=0;        next[0]:=l1;        for i:=1 to l1-1 do        begin                if (j<0)or(i+next[i-a]>=p) then                begin                        if (j<0) then                        begin                                j:=0;                                p:=i;                        end;                        while (p《l1)and(j《l1)and(s1[p+1]=s1[j+1]) do                        begin                                inc(p);                                inc(j);                        end;                        next[i]:=j;                        a:=i;                end                else next[i]:=next[i-a];                dec(j);        end;        for i:=0 to l1-1 do write(next[i],' ');        j:=-1;        p:=0;        a:=0;        for i:=0 to l-1 do        begin                if (j<0)or(i+next[i-a]>=p) then                begin                        if (j<0) then                        begin                                j:=0;                                p:=i;                        end;                        while (p《l)and(j《l1)and(s[p+1]=s1[j+1]) do                        begin                                inc(p);                                inc(j);                        end;                        extand[i]:=j;                        a:=i;                end                else extand[i]:=next[i-a];                dec(j);        end;        writeln;        for i:=0 to l-1 do write(extand[i],' ');end.