标签:mat https strlen blank pow lan else names void
标准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 }
标签:mat https strlen blank pow lan else names void
原文地址:https://www.cnblogs.com/ainiyuling/p/11136932.html