完整代码:
注意:这里所有数组有效信息都是从第二个数据开始。
#include<stdio.h>
#include<string.h>
#define N 100
void getnext(char* c,int next[]){
int i=1,j=0,m;
next[1]=0;
m=strlen(c);
while(i<m-1){
if(j==0||c[i]==c[j]){
i++;
j++;
next[i]=j;
}
else
j=next[j];
}
}
void print(int next[],char *a){
int i;