KMP实现
来源:互联网 发布:用mac怎么该音频格式 编辑:程序博客网 时间:2024/04/29 22:11
KMP最难的部分就是next数组的实现,涉及到数学的证明和对next数组的理解
// KMP.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "string.h"#include "stdio.h"#define MAX 10char pattern[MAX] = "ABAB";char Str[] = "ABCDABDABCDABD";char next[MAX];//前一个字串的最长前后缀公共串void GetNext(){int pLen = strlen(pattern); next[0] = -1; int k = -1; int j = 0; while (j < pLen - 1) { //p[k]表示前缀,p[j]表示后缀 if (k == -1 || pattern[j] == pattern[k]) { ++j; ++k; next[j] = k; } else { k = next[k]; } } }void KMP(){int len = strlen(Str);int plen = strlen(pattern);int j;for (int i = 0; i < len;){for (j = 0; j < plen; j++){if (Str[i+j] != pattern[j])break;}if (j == plen)printf("find\n");i += j - next[j];}}int main(int argc, char* argv[]){GetNext();KMP();return 0;}
0 0
- KMP实现
- KMP实现
- KMP实现
- kmp入门--kmp c++实现
- [数据结构]KMP算法实现
- KMP算法的实现
- 转载c++实现kmp
- KMP算法实现
- KMP算法实现
- KMP 算法实现
- kmp算法实现
- KMP算法实现
- KMP算法和实现
- KMP算法实现
- KMP实现(二)
- KMP算法及实现
- KMP算法的实现
- KMP算法实现
- Android Zxing 添加闪光灯功能
- Dom编程(有子菜单的导航条 和 选项卡)
- 记录个博客
- boa源码分析
- 调试_ _FILE__,__LINE__
- KMP实现
- Android之使用Android-query框架进行开发
- JS中showModalDialog 详细使用
- LeetCode-Largest Rectangle in Histogram
- HDU4915:Parenthese sequence(贪心)
- 传纸条
- PostgreSQL学习之一
- UVA - 10917 Walk Through the Forest (最短路+DP)
- for 循环创建button 算法