Exkmp

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值