Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int BM(string s, string t) {
- int n = s.size();
- int m = t.size();
- vector<int> v;
- for (int i = 0; i <= n - m; ++ i) {
- if (s[i] == t[0])
- v.push_back(i);
- }
- for (int i = 0; i < v.size(); ++ i) {
- int j = m - 1;
- while (j >= 0 && s[v[i] + j] == t[j]) j--;
- if (j == -1) return v[i];
- }
- return -1;
- }
- int main() {
- string s, t;
- cin >> s >> t;
- cout << BM(s, t) << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment