Advertisement
Rentib

szukanie

Mar 13th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. ios_base::sync_with_stdio(0);
  5. cin.tie(0);
  6. string w, s;
  7. cin >> w >> s;
  8. s = w + '#' + s;
  9. int n = s.size(), k = w.size();
  10. vector<int> p(n), v;
  11. for(int i = 1;i < n;i++){
  12. int j = p[i - 1];
  13. while(j > 0 && s[i] != s[j])
  14. j = p[j - 1];
  15. if(s[i] == s[j])
  16. j++;
  17. p[i] = j;
  18. if(j == k)
  19. v.push_back(i - 2 * k + 1);
  20. }
  21. cout << v.size() << '\n';
  22. for(auto i : v)
  23. cout << i << ' ';
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement