标签:
Description
Input
Output
Sample Input
abcd aaaa ababab .
Sample Output
1 4 3
Hint
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 5 const int maxn=1000005; 6 7 int next[maxn]; 8 9 void getnext(char str[]) 10 { 11 int i,j; 12 int len=strlen(str); 13 i=0;j=-1; 14 next[i]=j; 15 while(i<=len) 16 { 17 if(j==-1||str[i]==str[j]) 18 { 19 i++; 20 j++; 21 next[i]=j; 22 } 23 else 24 j=next[j]; 25 } 26 } 27 28 int main() 29 { 30 //freopen("in.txt","r",stdin); 31 int cnt,i; 32 char s[maxn]; 33 while(scanf("%s",s)&&strcmp(s,".")!=0) 34 { 35 getnext(s); 36 int len=strlen(s); 37 if(len%(len-next[len])==0) 38 printf("%d\n",len/(len-next[len])); 39 else 40 printf("%d\n",1); 41 } 42 return 0; 43 }
标签:
原文地址:http://www.cnblogs.com/homura/p/4711084.html