| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
不是应该用KMP吗???#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
char a[1000005];
int next[1000005];
void getnext()
{
int len=strlen(a);
next[0]=0,next[1]=0;
for(int i=1;i<len;i++){
int j=next[i];
while(j&&a[i]!=a[j]) j=next[j];
next[i+1]=a[i]==a[j]?j+1:0;
}
int maxans=len-next[len];
if((len%maxans)) puts("1");
else printf("%d\n",len/maxans);
}
int main()
{
while(scanf("%s",a))
if(a[0]!='.') getnext();
else return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator