| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 47748 | Accepted: 19902 | 
Description
Input
Output
Sample Input
abcd aaaa ababab .
Sample Output
1 4 3
Hint
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int next[1000002];
char a[1000002];
void getNext()
{
    int i=-1,j=0;
    next[0]=-1;
    int cnt=0;
    while(a[j])
    {
        if(a[i]==a[j]||i==-1)
        {
            next[++j]=++i;
        }
        else
            i=next[i];
    }
}
int main()
{
    while(scanf("%s",a)!=EOF)
    {
        if(a[0]==‘.‘) break;
        int m=strlen(a);
        getNext();
        int cc=1;
        if(m%(m-next[m])==0)  //如果条件满足,m-next[m]为最短循环字串,然后求出该字符串由多少个最短循环字串构成
            cc=m/(m-next[m]);
        cout<<cc<<endl;
    }
    return 0;
}
原文:http://www.cnblogs.com/f-society/p/6701809.html