KMP —— next数组
2017-02-14 18:15
197 查看
求KMP算法中next数组
代码如下
#include "iostream" #include <cstring> using namespace std; typedef char* String; void Get_Next(String T, int *next) { int j, k; j = 0; k = -1; next[0] = -1; while(j < strlen(T)) { if(k == -1 || T[j] == T[k]) { j++; k++; next[j] = k; } else { k = next[k]; } } } void main() { cout << "/** 说明:next就是输入的那一串字符每一个字符多对应的下标 ***/" << endl; int N; cout << "请输入你想测试的次数:" << endl; cin >> N; while (N--) { cout << endl; cout << "请输入一串字符:" << endl; char str[255]; cin >> str; int next[255]; int i = 1; //cout << strlen(str) << endl; Get_Next(str, next); cout << "每一个字符对应的next的值为:" << endl; for (i = 0; i < strlen(str); i++) { printf("%d ", next[i]); } } cout << endl; system("pause"); }
相关文章推荐
- 【KMP】多种KMP算法next数组的求解
- 【经典算法】——KMP,深入讲解next数组的求解
- nyoj 2340 最小循环节(KMP之next数组的应用)
- hdu 1358 Period(KMP之next数组)
- poj 1961 Period [kmp, next数组的用法]
- KMP(内含next数组讲解) —— 剪花布条 ( HDU 2087 )
- kmp的next数组值得求法
- KMP 模板 next数组
- 【经典算法】——KMP,深入讲解next数组的求解
- 【经典算法】——KMP,深入讲解next数组的求解
- HDOJ1358 Period 【KMP next数组应用】
- kmp的next数组值得求法
- KMP中next数组的理解
- 【经典算法】——KMP,深入讲解next数组的求解
- KMP之next[]数组的求解
- POJ - 2752 Seek the Name, Seek the Fame(KMP next数组的理解)
- 【HDU 3336】Count the string 【KMP next数组巧妙应用】
- HDU3336-Count the string-KMP(next数组理解)
- nyoj 2340 最小循环节(KMP之next数组的应用)
- hdu 1358 Period(KMP之next数组)