标签:kmp page sky std ref cstring com arch oid
详解:
http://www.cppblog.com/oosky/archive/2006/07/06/9486.html
http://www.matrix67.com/blog/archives/115
http://blog.csdn.net/v_july_v/article/details/7041827
http://kb.cnblogs.com/page/176818/
白书上的代码:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn=1000006; const int maxm=10004; char p[maxm],t[maxn]; int f[maxm]; void getfail(char* p,int* f){ int m=strlen(p); f[0]=0;f[1]=0; for(int i=1;i<m;i++){ int j=f[i]; while(j&&p[i]!=p[j]) j=f[j]; f[i+1]=(p[i]==p[j]?j+1:0); } } int find(char* t,char* p,int* f){ int n=strlen(t),m=strlen(p); getfail(p,f); int j=0; for(int i=0;i<n;i++){ while(j&&p[j]!=t[i]) j=f[j]; if(p[j]==t[i]) j++; if(j==m) return i-m+1;//下标从0开始的位置 } return -1; } int main() { return 0; }
标签:kmp page sky std ref cstring com arch oid
原文地址:http://www.cnblogs.com/--ZHIYUAN/p/6411249.html