## 缺氧

2015/12/03 Go the extra mile.

# POJ-2406-kmp求最小循环节

http://poj.org/problem?id=2406

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#define  inf 0x7fffffff
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const int maxn = 1000005;
using namespace std;

int nextval[maxn];
void get_next(char *t,int len)	//失配函数

{
int i,j;
i=1;
nextval[1]=0;
j=0;
while(i<len)
{

if (j==0||t[i]==t[j])
{
j++;
i++;
//	if (t[i]!=t[j])
nextval[i]=j;
//	else
//		nextval[i]=nextval[j];

}
else
j=nextval[j];
}

}

char tm[maxn];  //主串
char nm[maxn];

int judge(int x)
{
return 0;
}
int main( )
{

while(scanf("%s",tm+1)!=EOF)
{
if (strcmp(tm+1,".")==0) break;
int len=strlen(tm+1);
get_next(tm,len);
int maxx=nextval[len];
int ans;
if (len%(len-maxx)==0&& tm[len]==tm[nextval[len]])
ans=len/(len-maxx);
else
ans=1;

printf("%d\n",ans);

}
return 0;
} 

07-24 248

02-11 1862

08-21 617

05-26 586

08-14 1560

09-22 464

08-31 524

05-07 534

02-25 961

11-04 920