-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboyer-moore.cpp
More file actions
59 lines (48 loc) · 1.25 KB
/
boyer-moore.cpp
File metadata and controls
59 lines (48 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Boyer-Moore Algorithm
// cannot understand how to implement!!
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define endl '\n'
using namespace std;
int skip(string str, char c) {
int N = str.size();
REP(i, 0, N) { // search backward
if (str[N-i-1] == c)
return i;
}
return N;
}
vector<int> boyer_moore(string str, string pattern) {
// vector<int> ans;
// int N = str.size();
// int M = pattern.size();
// REP(i, M-1, N) {
// if (str[i] == str[M-1]) {
// REP(j, 1, M) {
// if (str[i-j] != str[M-1-j]) {
// i += skip(pattern, str[i-j]) - j; // HOW?
// break;
// }
// }
// } else {
// i += skip(pattern, str[i]);
// }
// }
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string str, pattern;
getline(cin, str);
getline(cin, pattern);
vector<int> ans = boyer_moore(str, pattern);
REP(i, 0, ans.size()) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
}