18字符串模式匹配kmp算法求next数组

/*
姓名:高万禄
名称:求next数组
日期:2020/2/4 
*/ 
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
	 char test[11];
	 int next[11],j=1,k=0;
	 scanf("%s",test);
	 next[1]=0;
	 while(j<11)
	 {
	 if(k==0||test[k]==test[j])
	 {
	 next[++j]=++k;	
	 }
	 else
	 {
	 k=next[k];	
	 }
       }
	for(j=1;j<11;j++)
	{
		printf("%-3d",next[j]);
	}
	printf("\n");	
	return 0;
} 

发布了24 篇原创文章 · 获赞 0 · 访问量 76

猜你喜欢

转载自blog.csdn.net/qq_45812941/article/details/104413682