Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- vector<int> zf(const string &s)
- {
- int n = s.size();
- vector<int> res(n);
- for (int i = 1; i < n; ++i)
- {
- while (i + res[i] < n && s[res[i]] == s[i + res[i]])
- ++res[i];
- }
- return res;
- }
- int main()
- {
- string s;
- cin >> s;
- for (auto x : zf(s))
- cout << x << ' ';
- cout << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement