Exkmp

xiaoxiao2021-02-28  107

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.
转载请注明原文地址: https://www.6miu.com/read-72501.html

最新回复(0)