KMP匹配问题
#include<stdio.h>
#include<string.h>
int m,n;
int a[1000002],b[10002],next[10002];
void getnext(const int *p)
{
int i,j;
next[0]=-1;
i=0;j=-1;
while(i!=m)
{
if(j==-1||p[i]==p[j])
{
i++;j++;
if(p[i]!=p[j])
next[i]=j;
else next[i]=next[j];
}
else j=next[j];
}
}
int KMP(const int *s,const int* p)
{
int i=0,j=0;
while(i!=n&&j!=m)
......
阅读全文