#include #include #include #include using std::cin; using std::string; using std::vector; vector find_pattern(const string& pattern, const string& text) { vector result; string s = pattern + "$" + text; vector prefixes(s.size()); int border = 0; int ps = pattern.size(); for (int i = 1; i < s.size(); i++) { while ((border > 0) && (s[i] != s[border])) border = prefixes[border - 1]; prefixes[i] = border = ((s[i] == s[border]) ? (border + 1) : 0); if (border == ps) result.push_back(i - 2 * ps); } return result; } int main() { string pattern, text; cin >> pattern; cin >> text; vector result = find_pattern(pattern, text); for (int i = 0; i < result.size(); ++i) { printf("%d ", result[i]); } printf("\n"); return 0; }