【题意】
求对于一个字符串满足前n个字符全等于后n个字符的n有哪些
【输入】
多组数据,每行一个字符串(不超过400000位)
【输出】
每组数据一行,输出一行数表示从小到大满足的n
kmp求next数组,之后倒着扫描即可……
不知为何这种题也能wa很多次……
program poj2752;
var
tot,n,i,j,k:longint;
s:ansistring;
ans,next:array [0..400003] of longint;
begin
next[1]:=0;
while not seekeof do
begin
readln(s);
n:=length(s);
i:=1;
j:=0;
while i<n do
if (j=0)or(s[i]=s[j]) then
begin
inc(i);
inc(j);
next[i]:=j;
end
else
j:=next[j];
tot:=0;
i:=n;
while (i<>0) do
begin
if s[i]=s[n] then
begin
inc(tot);
ans[tot]:=i;
end;
i:=next[i];
end;
for i:=tot downto 1 do
begin
write(ans[i]);
if i<>1 then write(' ');
end;
writeln;
end;
end.