Power Strings

 

题面

标准kmp

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<cmath>
 6 #include<queue>
 7 using namespace std;
 8 int next[1000001];
 9 char s[1000001];
10 void gt(){
11     int i=0,j=-1;
12     next[0]=-1;
13     int len=strlen(s);
14     while(i<len){
15         if(s[i]==s[j]||j==-1){
16             i++;
17             j++;
18             next[i]=j;
19         }
20         else
21             j=next[j];
22     }
23 }
24 int main(){
25     while(scanf("%s",s)>0){
26         if(s[0]=='.'){
27             break;
28         }
29         int len=strlen(s);
30         gt();
31         if(len%(len-next[len])==0){
32             printf("%d\n",len/(len-next[len]));
33         }
34         else{
35             printf("1\n");
36         }
37     }
38     return 0;
39 }

 

posted @ 2019-07-05 10:46  [jackeylove]  阅读(225)  评论(0编辑  收藏  举报