典型的用kmp求循环节的题目,套用模板即可~
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <iostream>
using namespace std;
#define maxn 1000050
char str[maxn]={0};
int next[maxn]={0};
int main(){
while(scanf("%s",&str)){
if(str[0]=='.')
break;
memset(next,0,sizeof(next));
int len = strlen(str);
int j=-1;
next[0] = -1;
for(int i=0;i<len;){
if(j==-1||str[i]==str[j])
next[++i]=++j;
else
j = next[j];
}
if(len%(len-next[len])==0)
printf("%d\n",len/(len-next[len]));
else
printf("1\n");
}
return 0;
}