Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication3.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- #include "pch.h"
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- int Boyer_Mur(string s, string t) {
- vector<int> offsets;
- for (int i = 0; i <= s.size() - t.size(); ++i)
- if (s[i] == t[0])
- offsets.push_back(i);
- for (int i = 0; i < offsets.size(); ++i) {
- int j = offsets[i] + t.size() - 1;
- for (int k = t.size() - 1; k >= 0 && s[j] == t[k]; --j, --k);
- if (j == offsets[i] - 1) return offsets[i];
- }
- return -1;
- }
- int main() {
- string a = "abcafdfaecabd";
- string b = "abcabd";
- cout << Boyer_Mur(a, b) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement