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