首页 > 其他 > 详细

poj 1961 KMP运用之循环节的问题

时间:2015-01-27 15:01:31      阅读:288      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;

char str[1000010];
int next[1000010];
int get_next(int len)
{
	next[0]=-1;
	int i=0,k=-1;
	while(i<len)
	{
		if(k==-1||str[i]==str[k])
		{
			i++;
			k++;
			next[i]=k;
		}
		else k=next[k];
	}
	return 0;
}
int main()
{
	int n,j,i,d=1;
	while(scanf("%d",&n),n)
	{
		scanf("%s",str);
		printf("Test case #%d\n",d++);
		get_next(n);
		for(i=2;i<=n;i++)
		{
			int t=i-next[i];
			if(i%t==0&&t!=i) printf("%d %d\n",i,i/t);
		}
		printf("\n");
	}
}

poj 1961 KMP运用之循环节的问题

原文:http://blog.csdn.net/zxf654073270/article/details/43193929

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!