题目链接:http://poj.org/problem?id=2406
参考:http://blog.csdn.net/u010489766/article/details/9272489
#include<stdio.h>
#include<string.h>
int next[1100000];
char str[1100000];
int len;
void get_next()
{
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()
{
memset(str,0,sizeof(str));
while(scanf("%s",str) != EOF && *str != '.')
{
memset(next,-1,sizeof(next));
len = strlen(str);
get_next();
int leng = len - next[len];
if( len % leng == 0 && next[len-1] != -1)
printf("%d\n",len/leng);
else //如果不能分成多子字符串的话,就只能分成1个字符串了,就是自己
printf("1\n");
memset(str,0,sizeof(str));
}
return 0;
}