算法细节详见和
#include#include #define N 7#define M 15void showpset(int* a);void cal_pset(char* a, int* p,int n);int KMP(char* a,char* b,int* P);int main(void){ char a[M]={'a','b','a','c','a','b','a','a','b','a','b','a','c','b','d'}; char b[N]={'a','b','a','b','a','c','b'}; int P[N]={0}; int i=1; int index=-1; cal_pset(b,P,N); index=KMP(a,b,P); //showpset(P); printf("%d ",index); system("pause"); return 0;}int KMP(char* a,char* b,int* P){ int i=0,j=0; int flag=0; while(i