字符串匹配KMP学习

2014-11-23 19:04:12 · 作者: · 浏览: 18

学习KMP的博客链接 博主讲解的很到位,排版赏心悦目,在此感谢。吐槽一下,博客园的的博客皮肤样式真是比CSDN好看几百倍。

#include 
  
   
#include 
   
     using namespace std; int matcher(const char* s,const char* p){ int i=0; int j=0; while( s[i]!='\0' && p[j]!='\0'){ if(s[i]==p[j]){ i++; j++; } else{ i=i+1-j; j=0; } } if(p[j]=='\0'){ return i-strlen(p); } else return -1; } void getNext(const char *p,int *next){ int i=0; int j=-1; int n=strlen(p); next[0]=-1; while(i