Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int main() {
- string s;
- cin >> s;
- size_t p = s.length();
- vector <long long> pref_function(p, 0);
- for (size_t i = 1; i < p; ++i){
- size_t k = pref_function[i - 1];
- while ((k > 0) && (s[i] != s[k])) {
- k = pref_function[k - 1];
- }
- if (s[i] == s[k]) {
- k++;
- }
- pref_function[i] = k;
- }
- char ch;
- cin.get(ch);
- long long f = 0;
- size_t i = 0;
- cin.get(ch);
- while (ch != '\n'){
- while ((f > 0) && (s[f] != ch)){
- f = pref_function[f - 1];
- }
- if (s[f] == ch) {
- f++;
- }
- if (f == p) {
- cout << i - p + 1 << endl;
- }
- i++;
- cin.get(ch);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement