KMP算法
来源:互联网 发布:php属于什么专业 编辑:程序博客网 时间:2024/05/16 14:19
int*next = NULL;
void get_next(constchar * p)
{
assert(p != NULL);
int m=strlen(p);
next= (int*)malloc(m*sizeof(int));
if(next==NULL)
{
thrownew std::exception(" malloc failed!");
}
int k=0;
next[0]= 0;
next[1]= 0;
for(int i= 2; i <= m; ++ i)
{
while(k>0 &&*(p + k+1) != *(p + i))
{
k= next[k];
}
if(*(p+ k+ 1) == *(p + i))
{
k++;
}
next[i]= k;
}
}
int kmp_match(constchar * T, const char * P)
{
assert(T != NULL &&P != NULL);
int n=strlen(T);
int m=strlen(P);
int k=0;
for(int i= 1; i <= n; i++)
{
while(k>0 &&T[i] != P[k +1])
{
k= next[k];
}
if(T[i]==p[k + 1])
{
k++;
}
if(k==m)
{
printf("find it at %d\n", i);
k=0;
}
}
free next;
return0;
}
- KMP算法详解 【KMP】
- 【KMP】KMP算法模板
- KMP hihoCoder1015 KMP算法
- kmp算法
- KMP算法
- KMP算法
- KMP算法
- KMP算法
- KMP 算法
- kmp算法
- KMP算法
- kmp算法
- KMP算法
- KMP算法
- kmp算法
- kmp算法
- KMP算法
- KMP算法
- poj 2068 NIM (博弈DP)
- SIFT算法的应用--目标识别之Bag-of-words模型
- 数组表示数的下一个比它大的最小的置换
- spoj 2
- C++标准模板库分析之三
- KMP算法
- 信息检索-Bag of words模型
- win32多线程学习笔记
- 如何应对保研面试
- 黑马程序员-我的摘录- 浅谈C#中的枚举
- 问答邮件整理记录——HttpURLConnection下载网络文件
- 字符串面试题
- project euler problem 15
- dsoframer.ocx控件编辑后保存在服务器端的简单方法