Professional Documents
Culture Documents
Rabin Karp
Rabin Karp
#include <cstring>
if (substringHash == patternHash) {
// Перевірка решти рядків зразка
bool match = true;
for (int k = 1; k < m; ++k) { //O((m-1)m) |||
substring = &text[i + k][j];
substringHash = calculateHash(substring); //O(m) |||
if (substringHash != pattern[k]) {
match = false;
break;
}
}
if (match) {
found = true;
cout << "The pattern was found starting in the row number " << i
+ 1 << ", position in the starting row is " << j + 1 << endl;
}
}
}
}
if(!found){
cout << "The pattern was not found in the array" << endl;
}
}
int main() {
int n, m;
cout << "Enter the size of array n - ";
cin >> n;
return 0;
}