题目大意:问一个字符串由多少个循环节构成

解题思路:循环节和next的关系

#include <cstdio>
#include <cstring>
const int N = 1000010;
char str[N];
int len;
int next[N];

void getFail() {
    len = strlen(str);
    int i = 0, j = -1;
    next[0] = -1;
    while (i < len) {
        if (j == -1 || str[i] == str[j]) {
            i++; j++;
            next[i] = j;
        }
        else j = next[j];
    }
}

int main() {
    while (scanf("%s", str) && str[0] != '.') {
        getFail();
        if (len % (len - next[len]) == 0) 
            printf("%d\n", len / (len - next[len]));
        else printf("1\n");
    }
    return 0;
}