求一个字符串的循环节为多大,直接用kmp的next的数组求法写
#include <stdio.h>
#include <string.h>
using namespace std;
char s[1123456];
int next[1123456];
int main()
{
while(~scanf("%s", s)){
if(s[0] == '.'){
break;
}
int i = 0;
int j = -1;
next[0] =-1;
int n = strlen(s);
while(i < n){
if(j == -1||s[i] == s[j]){
i++;
j++;
next[i] = j;
}else {
j = next[j];
}
}
if(n%(n-next[n])==0){
printf("%d\n", n/(n-next[n]));
}else{
printf("1\n");
}
}
return 0;
}