题意:问串S 最多能表示成多少个串的重复 输出重复的最大值
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 1000000 + 5;
int NEXT[maxn];
char str[maxn];
int main(){
while( scanf("%s",str) && str[0] != '.' ){
int n = strlen(str);
NEXT[0] = NEXT[1] = 0;
for(int i = 1;i < n;++i){
int j = NEXT[i];
while( j && str[i] != str[j] ) j = NEXT[j];
NEXT[i + 1] = str[i] == str[j] ? j + 1 : 0;
}
int ans;
if(NEXT[n] == 0){
ans = 1;
}
else{
if(n % (n - NEXT[n]) == 0){
ans = n / (n - NEXT[n]);
}
else ans = 1;
}
printf("%d\n",ans);
}
return 0;
}