PR值算法最近是否改动过?

来源:百度知道 编辑:UC知道 时间:2024/06/08 07:23:44
有谁知道PR值算法最近是否改动过?

不知道,拿分走人。/*************************************************************************
* Function Name:
* i = IndexKMP();
*
* Parameters:
* char *S - 主串或文本串
* char *P - 模式串
* int pos - 起始查询的位置
*
* Return Value:
* int
*
* Description:
* 一般的kmp算法实现模式匹配.
************************************************************************/
int IndexKMP(const char* S, const char* P, int pos)
{ // 利用模式串P的next函数求P在主串S中第pos个字符之后的位置的KMP算法
// 其中, P非空, 1≤pos≤strlen(S)
assert(S && P && "Primary String S or Pattern P is NULL in IndexKMP()!\n");

int i = pos - 1, j = 0; // 从第1个字符开始,i为主串的索引,j为模式串的索引
int n = strlen(S), m = strlen(P); // 取串长度

if (n < m) return 0; // 隐含条件:模式串的长度必须小于或等于主串的长度

assert((pos >= 1) && (pos <= n) &&
"Parameter pos is not in the domain[1, strlen] in IndexKMP()!\n");

int *next = NULL; // 生成