hoj1952 power strings

/*This Code is Submitted by billforum for Problem 1952 at 2012-02-17 13:29:48*/
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <string.h>
using namespace std;

const int N=1000005;

int next[N];


int main()
{
    string str;
    while(cin>>str)
    {
        if(str[0]=='.') break;
        for(int i=0;i<=str.size();i++)
        next[i]=0;
        next[0]=-1;
        int i=0,j=-1,len=str.size();
        while(i<len)
        {
            if(j==-1||str[i]==str[j])
            {
                i++;
                j++;
                next[i]=j;
            }
            else j=next[j];
        }
        j=i-next[i];
        cout<<i/j<<endl;
    }
    return 0;
}


 

posted @ 2012-02-17 13:32  wuzhibin  阅读(118)  评论(0)    收藏  举报