#include<iostream>
#include<string>
using namespace std;
string s;
int nex[400010];
void getNext()
{
int i = 0, j = -1;
int len_s = s.length();
nex[0] = -1;
while(i < len_s)
{
if(j == -1 || s[i] == s[j])
{
j++;
i++;
nex[i] = j;
}
else j = nex[j];
}
}
void solve(int len)
{
if(nex[len] > 0)
{
solve(nex[len]);
printf("%d ", nex[len]);
}
}
int main()
{
while(getline(cin, s))
{
getNext();
int len = s.length();
solve(len);
printf("%d ", len);
printf("\n");
}
//getchar();
return 0;
}
相关文章
- 03-26POJ 2752 Seek the Name, Seek the Fame KMP
- 03-26POJ-2752 Seek the Name, Seek the Fame 字符串问题 KMP算法 求前后缀串相同数木
- 03-26poj 2752 Seek the Name, Seek the Fame【KMP算法分析记录】【求前后缀相同的子串的长度】
- 03-26Seek the Name, Seek the Fame
- 03-26POJ2752 Seek the Name, Seek the Fame
- 03-26Seek the Name, Seek the Fame
- 03-26D - Seek the Name, Seek the Fame
- 03-26Seek the Name, Seek the Fame POJ - 2752
- 03-26POJ 2752 Seek the Name, Seek the Fame(next数组的理解)
- 03-26【hash】Seek the Name, Seek the Fame