标签:
Description
Input
Output
Sample Input
ababcababababcabab aaaaa
Sample Output
2 4 9 18 1 2 3 4 5
Source
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<set> using namespace std; char s[410000]; int next[410000],l; void f(int t) { if(t == 0) return; f(next[t]); if(t!=l)printf("%d ",t); else printf("%d\n",t); } int main() { int i,j,k; while(scanf("%s",s+1)!=EOF) { l = strlen(s+1); next[1] = 0; for(i = 2;i<l+1;i++) { int t = next[i-1]; while(t&&s[i]!=s[t+1]) t = next[t]; if(s[i] == s[t+1]) t++; next[i] = t; } f(l); } return 0; }
poj2752Seek the Name, Seek the Fame
标签:
原文地址:http://www.cnblogs.com/wos1239/p/4389481.html