kmp算法模版,网上kmp的版本太多晕了.........
code
#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <limits>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string.h>
#include <iostream>
#include <algorithm>
#define Si set<int>
#define LL long long
#define pb push_back
#define PS printf(" ")
#define Vi vector<int>
#define LN printf("\n")
#define lson l,m,rt << 1
#define rson m+1,r,rt<<1|1
#define SD(a) scanf("%d",&a)
#define PD(a) printf("%d",a)
#define SET(a,b) memset(a,b,sizeof(a))
#define FF(i,a) for(int i(0);i<(a);i++)
#define FD(i,a) for(int i(a);i>=(1);i--)
#define FOR(i,a,b) for(int i(a);i<=(b);i++)
#define FOD(i,a,b) for(int i(a);i>=(b);i--)
#define readf freopen("input.txt","r",stdin)
#define writef freopen("output.txt","w",stdout)
const int maxn = 1000001;
const long long BigP=999983;
const int INF = 0x3fffffff;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const double pi = acos(-1.0);
const double eps= 1e-7;
using namespace std;
int next[maxn];
int getNext(char *p,int *next){
int i=0,j=-1;
next[0]=-1;
int len=strlen(p);
while(i<len){
if( j==-1 || p[i]==p[j]){
i++;j++;
next[i]=j;
}else j=next[j];
}
int x=len-next[len];
if(len%x==0) return len/x;
return 1;
}
int main()
{
char s[maxn];
while(~scanf("%s",s)){
if(s[0]=='.')
break;
printf("%d\n",getNext(s,next));
}
return 0;
}