标签:
Description
Input
Output
Sample Input
abcd aaaa ababab .
Sample Output
1 4 3
Hint
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char s[1000005]; int fail[1000005]; int len; void get_fail(); int main() { while(scanf("%s",s+1),s[1]!=‘.‘) { len=strlen(s+1); get_fail(); int ans=1; //ÀûÓÃfail[len] if(len%(len-fail[len])==0) ans=len/(len-fail[len]); printf("%d\n",ans); } } void get_fail() { memset(fail,0,sizeof(fail)); fail[0]=-1; for(int i=1;i<=len;i++) { int p=fail[i-1]; while(p>=0&&s[p+1]!=s[i]) p=fail[p]; fail[i]=p+1; //cout<<i<<" "<<fail[i]<<endl; } }
标签:
原文地址:http://www.cnblogs.com/hr974041087/p/5742993.html