Laughing

 

hdu 1358

http://acm.hdu.edu.cn/showproblem.php?pid=1358

 

#include<stdio.h>
#include<string.h>
int next[1000001],i,j,n,tem,k;
char a[1000001];
void get_next()
{
j=next[0]=-1;
for(i=0;i<n;)
{
if(j==-1||a[i]==a[j])
{
i++;j++;
//if(a[i]==a[j]) next[i]=next[j];
//else next[i]=j;
next[i]=j;
//if(j>0) printf("%d %d\n",i,j);
if(j&&i%(i-j)==0) printf("%d %d\n",i,i/(i-j)); //这里自己去体会吧
}
else j=next[j];
}
}
void main()
{
int ca=1;
while(scanf("%d",&n)&&n)
{
scanf("%s",&a);
printf("Test case #%d\n",ca++);
get_next();
printf("\n");
}
}

posted on 2012-03-22 21:52  巨富一生  阅读(137)  评论(0编辑  收藏  举报

导航