我从这个网站了解拉宾-卡普算法:https://www.geeksforgeeks.org/rabin-karp-algorithm-for-pattern-searching/
他们的算法的 C++ 代码如下:
#include <bits/stdc++.h>
using namespace std;
// d is the number of characters in the input alphabet
#define d 256
/* pat -> pattern
txt -> text
q -> A prime number
*/
void search(char pat[], char txt[], int q)
{
int M = strlen(pat);
int N = strlen(txt);
int i, j;
int p = 0; // hash value for pattern
int t = 0; // hash value for txt
int h = 1;
// The …Run Code Online (Sandbox Code Playgroud)