KMP算法
来源:互联网 发布:找淘宝客服工作 编辑:程序博客网 时间:2024/06/04 01:31
#include<stdio.h>#include<string.h>void makeNext(contant char p[],int next[]){//创建F int m=Strlen(p); int q,k; next [0]=0; for(q=1,k=0;q<m;++q){ while(k>0&&p[q]!=p[k]) k=next[k-1]; if(p[q]==p[k]){ k++ } next[q]=k; } } int kmp(const char T[],const char P[],int next []){ int n,m; int i,q; n=strlen(T); m=strlwn(P); makeNext(P,next); for(i=0,q=0;i<n;++i){ while(q>0&&P[q]!=T[i]) q=next[q-1]; if(P[q]==T[i]){ q++ } if(q==m){ printf("模式出现在 %d\n",(i-m+1)); } } } int main(){ int i; int next[20]={0}; char T[]="abcdefgabcdhrrhu"; char P[]="abcdhrr"; printf("%s\n",T); printf("%s\n",P); makeNext(P,next); for(i=0;i<strlen(P);++i){ printf("%d",next[i]); } printf("\n"); return 0; }
阅读全文
0 0
- KMP算法详解 【KMP】
- 【KMP】KMP算法模板
- KMP hihoCoder1015 KMP算法
- kmp算法
- KMP算法
- KMP算法
- KMP算法
- KMP算法
- KMP 算法
- kmp算法
- KMP算法
- kmp算法
- KMP算法
- KMP算法
- kmp算法
- kmp算法
- KMP算法
- KMP算法
- JSONP 应用
- 【模板】高精度
- 快速沃尔什变换详解(FWT)
- 51nod 1491 黄金系统
- 【经典必学】常用开源框架中设计模式使用分析
- KMP算法
- NWERC2015 Elementary Math
- 怎样安装最新版的Appium
- CUDA编程实践(一)
- 并查集之POJ--1308--Is It A Tree?
- CSS基础(一)
- MemSQL Start[c]UP 3.0
- Codeforces Gym 101164I Cubes
- HDU 5974 A Simple Math Problem