| ||||||||||
| 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 | |||||||||
高手帮小弟看一下吧。。re了一晚了。。KMP觉得没什么问题啊。。55#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void kmp(char *a,int *next)
{
int i=1,j=0;
next[1]=0;
while(i<=next[0])
{
if(j==0||a[i]==a[j])
{
++i;++j;
next[i]=j;
}
else
j=next[j];
}
}
int main()
{
char cha[100];
int next[100];
int i,num,k;
while(1)
{
i=1;num=0; k=0;
scanf("%c",&cha[i]);
if(cha[i]=='.')
break;
while(cha[i]!='\n')
{
scanf("%c",&cha[++i]);
}
i=i-1;
next[0]=i;
kmp(cha,next);
k=i-next[i];
if(i%k!=0||cha[next[i]]!=cha[i])
printf("1\n");
else
printf("%d\n",i/k);
}
return 1;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator