[求助]这个KMP模式匹配,哪里错了
#include "iostream"#include "stdlib.h"
#include "stdio.h"
#define N 255
using namespace std;
typedef unsigned char SString[N+1];
SString T,S;
void GetNext(SString &T,int *next) {
int i=1,j=0;
next[i]=0;
while(i<T[0])
if(j==0||T[i]==T[j]){
++i;++j;
next[i]=j;}
else j=next[j];
}
int IndexKMP(SString &S,SString &T,int *next) {
int i=1,j=1;
while(i<S[0]||j<T[0])
if(j==0||S[i]==T[j]){
++i;++j;
}
else j=next[j];
if(j>T[0]) return i-T[0];
else return 0;
}
void main(){
int k;
int next[N];
cin>>S;
cin>>T;
GetNext(T,next);
k=IndexKMP(S,T,next);
cout<<k;
}