Untitled
unknown
plain_text
a year ago
1.7 kB
3
Indexable
Never
#include <bits/stdc++.h> using namespace std; #define ll long long #define EPS 1e-9 #define mod 1000000007 // #define mod 998244353 #define over 10000000000 #define sz(m) (ll)(m.size()) #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0)) #define fixed(n) fixed << setprecision(n) const ll inf = 1e18 + 5; // vector< vector <int> > nums( n , vector<int> (m)) ; // priority_queue<int, vector<int>, greater<int> > pq ; template <typename T = int> istream &operator>>(istream &in, vector<T> &v) { for (T &i : v) in >> i; return in; } template <typename T = int> ostream &operator<<(ostream &out, const vector<T> &v) { for (const T &x : v) out << x << ' '; return out; } void lol() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin), freopen("outputt.txt", "w", stdout), freopen("error.txt", "w", stderr); #endif } double log(double base, double x) { return (log(x) / log(base)); } int dx[4] = {1, 0, 0, -1}; int dy[4] = {0, 1, -1, 0}; ///////////////////////////////////////////////////////// int kmp(string &s) { int n = s.size(); vector<int> fail(n); int k = 0; for (int i = 1; i < n; i++) { while (k > 0 && s[k] != s[i]) { k = fail[k - 1]; } if (s[k] == s[i]) k++; fail[i] = k; } return fail.back(); } int main() { lol(); string s; while (cin >> s) { string x; string rv = s; reverse(rv.begin(), rv.end()); x = rv + '#' + s; int sm = kmp(x); for (int i = s.size() - sm - 1; i >= 0; i--) { s += s[i]; } cout << s << '\n'; } }