#include <stdio.h>
#include <string.h>
char a[2000000];
int next[2000000];
int len;
void getnext () //KMP的预处理函数. 我也不知道到叫不叫算法
{
int i=0,j=-1;
next[0]=-1;
while (i!=len)
{
if (j==-1||a[i]==a[j])
i++,j++,next[i]=j;
else
j=next [j];
}
}
bool is(double a)
{
if((int)a==a)
return 1;
return 0;
}
int main ()
{
int i;
int cas=1;
while (scanf("%d",&len),len)
{
scanf ("%s",a);
printf("Test case #%d\n",cas++);
getnext ();
for (i=2;i<=len;i++)
{
if(i/(i-next[i])>=2&&is((double)i/(i-next[i])))
printf("%d %d\n",i,i/(i-next[i]));
//i/(i-next[i]) 是用来计算有几个前缀子串的. i表示当前所在字符串的位置,next[i]是这个位置的重复子串长度. 具体调试看debug吧
}
puts("");
}
return 0;
}
hdu 1358 KMP中getnext函数的使用. 水体
最新推荐文章于 2022-05-15 22:02:01 发布