hipo 3 kmp算法
来源:互联网 发布:sql语句 drop 编辑:程序博客网 时间:2024/05/03 16:11
#include<iostream>#include<string>#include<map>using namespace std;void get_nextval(string& pattern, int* next){int i = 0, j = -1;next[0] = -1;while (pattern[i] != '\0'){if (j == -1 || pattern[i] == pattern[j]){++i;++j;next[i] = j;}elsej = next[j];}}int KMPMatch(string& s, string& p, int* next){int i, j, v = 0;i = 0;j = 0;get_nextval(p, next);while (i < s.length()){if (j == -1 || s[i] == p[j]){i++;j++;}else{j = next[j]; //消除了指针i的回溯}if (j == p.length()){++v;}}return v;}int main(){int n;cin >> n;string s, p;int next[10001] = { 0 };for (int i = 0; i < n; ++i){cin >> p;cin >> s;cout << KMPMatch(s, p, next) << endl;}return 0;}
0 0
- hipo 3 kmp算法
- HIPO图
- HIPO图
- 数据结构与算法3:KMP
- KMP算法详解 【KMP】
- 【KMP】KMP算法模板
- KMP hihoCoder1015 KMP算法
- kmp算法
- KMP算法
- KMP算法
- KMP算法
- KMP算法
- KMP 算法
- kmp算法
- KMP算法
- kmp算法
- KMP算法
- KMP算法
- Unity3d 5.0 动态播放视频,播放音乐
- wxWidgets(1) :mac下搭建wxWidgets 3.0 环境
- ImageLoader must be init with configuration before using 错误解决方法
- Python Intro - Solve problem of breaking gdb by python
- web开发首页初始化数据
- hipo 3 kmp算法
- 防止jquery文件重复引入的方法
- 创富论,实现与财富零距离接触
- MAKEWPARAM 宏
- javascript小结20150511
- textarea 动态限制字数
- 关于xml中控件属性的一些tip
- SQL中char、varchar、nvarchar的区别
- 1.环境搭建