|
|
back to boardNo subject Help me WA4? #include <iostream> #include <string> #include <string.h> #include <algorithm> using namespace std; string S, ss, s; int k, l, r, mid; int main(){ cin >> S; int n = S.size(); if(n == 1){ cout << S; return 0; } for (int i = n - 1; i >= 0; i --){ k = n - i; if(i - k >= 0){ ss = S.substr(i, k); s = S.substr(i - k, k); reverse(s.begin(), s.end()); //cout << ss << ' ' << s << endl; if(ss == s){ l = i - k; mid = i; r = i + k; continue; } } k --; if(i - k >= 0){ ss = S.substr(i + 1, k); s = S.substr(i - k, k); reverse(s.begin(), s.end()); //cout << ss << ' ' << s << endl; if(ss == s){ l = i - k; mid = i; r = i + k; } } } //cout << l << ' ' << r << endl; if(!l && !r || (l == 0 && r == n - 1)){ s = S.substr(0, n - 1); cout << S; reverse(s.begin(), s.end()); cout << s; } else{ s = S.substr(0, l); reverse(s.begin(), s.end()); cout << S << s; } return 0; } |
|
|