POJ - 2752 Seek the Name, Seek the Fame
https://vjudge.net/problem/POJ-2752
题目
分析
AC代码
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int N=4e5+10;
int ne[N];
string s;
int main()
{
while(cin>>s)
{
int n=s.size();
ne[0]=-1;
for(int i=0,j=-1;i<=n;)
{
if(j==-1 || s[i]==s[j])
{
i++,j++;
ne[i]=j;
}
else
j=ne[j];
}
int h[N];
int u=0;
int r=ne[n];
while(r)
{
h[u]=r;
u++;
r=ne[r];
}
for(int i=u-1;i>=0;i--)
printf("%d ",h[i]);
printf("%d\n",n);
}
return 0;
}
本文来自博客园,作者:斯文~,转载请注明原文链接:https://www.cnblogs.com/zhiweb/p/15483331.html