题目:
http://poj.org/problem?id=2752
#include <stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 400005
using namespace std;
int next[MAX];
char a[MAX];
int lena;
int aa[MAX];
void getnext(char *p){
int i = 0, j = -1;
next[0]= -1;
while(i != lena){
if(j ==-1 || p[i] == p[j])
next[++i] = ++j;
else
j =next[j];
}
}
int main(){
while(gets(a)){
lena =strlen(a);
memset(next,0,sizeof(next));
getnext(a);
int tt =lena;
intj=0;
for(;next[tt] != -1;tt = next[tt])
aa[j++] =tt;
for(inti = j-1;i>=0;i--)
printf("%d ",aa[i]);
printf("\n");
}
return 0;
}