标签:style class blog code http tar
又2b了一次……
1 var s:ansistring; 2 ans,pre:array[0..10000] of longint; 3 i,k,tot:longint; 4 procedure main; 5 begin 6 pre[1]:=0;k:=0; 7 for i:=2 to length(s) do 8 begin 9 while (k<>0) and (s[k+1]<>s[i]) do k:=pre[k]; 10 if s[k+1]=s[i] then inc(k); 11 pre[i]:=k; 12 end; 13 k:=pre[length(s)]; 14 tot:=0; 15 while k<>0 do 16 begin 17 inc(tot);ans[tot]:=k; 18 k:=pre[k]; 19 end; 20 for i:=tot downto 1 do write(ans[i],‘ ‘); 21 writeln(length(s)); 22 end; 23 begin 24 while true do 25 begin 26 readln(s);if s=‘‘ then break; 27 main; 28 end; 29 end.
标签:style class blog code http tar
原文地址:http://www.cnblogs.com/zyfzyf/p/3773203.html