Advertisement
StoneHaos

3_math

Feb 16th, 2021
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. // ConsoleApplication3.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include <vector>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. int Boyer_Mur(string s, string t) {
  12.     vector<int> offsets;
  13.     for (int i = 0; i <= s.size() - t.size(); ++i)
  14.         if (s[i] == t[0])
  15.             offsets.push_back(i);
  16.     for (int i = 0; i < offsets.size(); ++i) {
  17.         int j = offsets[i] + t.size() - 1;
  18.         for (int k = t.size() - 1; k >= 0 && s[j] == t[k]; --j, --k);
  19.         if (j == offsets[i] - 1) return offsets[i];
  20.     }
  21.     return -1;
  22. }
  23.  
  24. int main() {
  25.     string a = "abcafdfaecabd";
  26.     string b = "abcabd";
  27.     cout << Boyer_Mur(a, b) << endl;
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement