hiho-1015(c++)
2015-02-04 15:01
141 查看
20150204
KMP算法
字符串匹配
代码:
KMP算法
字符串匹配
代码:
#include <iostream> using namespace std; string mode; string source; int next[10000]; int counts; int main() { int n; cin >> n; for(int i = 0; i < n; i++){ cin >> mode >> source; counts = 0; for(int k = 1; k < mode.length(); k++){ if(mode[k]==mode[counts]){ counts++; }else{ counts = 0; if(mode[k]==mode[counts]){ counts++; } } next[k] = counts; } counts = 0; int n = 0; for(int j = 0; j < source.length(); j++){ if(source[j]==mode[counts]){ counts++; if(counts == mode.length()){ n++; counts = next[counts-1]; } }else{ if(counts == 0) continue; j--; counts = next[counts-1]; } } cout << n << endl; } return 0; }
相关文章推荐
- hiho一下1015
- 1015 Accepted 332K 32MS C++ 1740B
- (hiho一下第三周)#1015 KMP算法 【模版】
- hiho 1015 : KMP算法
- 1015C++中中文字符数组的关系
- Contest1015 - 2017年春季C++作业一 Problem A: 猜数游戏
- hiho一下 第174周 - Dice Possibility【概率dp的简单运用 java & c++】
- 1015. 德才论 (25)(C++)
- 【C++】浙大PAT (Basic Level)1015. 德才论 (25)
- neuq oj 1015同因查找C++
- hiho 1015 KMP
- PAT乙级(C++)1011-1015
- hiho一下第3周#1015 : KMP算法
- 【C++】PAT(basic level)1015. 德才论 (25)
- hiho-1082(c++)
- [Hiho]1015-KMP算法
- C++一本通题库1015
- Hiho_1015:KMP算法
- hiho-1014(c++)
- hiho 1015 KMP算法