Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <algorithm>
- using namespace std;
- vector<int> prefix_function(string s) {
- using namespace std;
- int n = s.length();
- vector<int> p(n);
- for (int i = 1; i < n; i++) {
- int j = p[i - 1];
- while (j > 0 && s[i] != s[j])
- j = p[j - 1];
- if (s[i] == s[j])
- ++j;
- p[i] = j;
- }
- return p;
- }
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- string str, rStr, uniStr;
- getline(fin, str);
- rStr = str;
- reverse(rStr.begin(), rStr.end());
- uniStr = rStr + "#" + str;
- vector<int> prefixVec = prefix_function(uniStr);
- for (int i = prefixVec[uniStr.size() - 1]; i < str.size(); i++) {
- fout << rStr[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement