yukicoder No.238
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
#include <functional> | |
#include <cmath> | |
#include <queue> | |
#include <stack> | |
#include <set> | |
#include <map> | |
#define repd(i,a,b) for (int i=(a);i<(b);i++) | |
#define rep(i,n) repd(i,0,n) | |
typedef long long ll; | |
using namespace std; | |
int inputValue(){ | |
int a; | |
cin >> a; | |
return a; | |
}; | |
template <typename T> | |
void output(T a, int precision) { | |
if(precision > 0){ | |
cout << setprecision(precision) << a << "\n"; | |
} | |
else{ | |
cout << a << "\n"; | |
} | |
} | |
int main() { | |
// source code | |
string s; | |
cin >> s; | |
vector<char> C; | |
int l = 0; | |
int r = (int)s.size() - 1; | |
bool check = false; | |
while (l <= r) { | |
if (s[l] == s[r]) { | |
C.push_back(s[l]); | |
l++, r--; | |
continue; | |
} | |
else{ | |
if (check) { | |
output("NA", 0); | |
return 0; | |
} | |
if (s[l + 1] == s[r]) { | |
C.push_back(s[l]); | |
check = true; | |
l++; | |
} | |
else if (s[l] == s[r - 1]) { | |
C.push_back(s[r]); | |
check = true; | |
r--; | |
} | |
else{ | |
output("NA", 0); | |
return 0; | |
} | |
} | |
} | |
string cstr = string(C.begin(), C.end()); | |
if (!check) { | |
string ret = cstr; | |
reverse(cstr.begin(), cstr.end()); | |
if (s.size() % 2 == 0) { | |
ret += "a" + cstr; | |
} | |
else{ | |
ret += cstr; | |
} | |
output(ret, 0); | |
return 0; | |
} | |
else{ | |
string ret = cstr; | |
reverse(cstr.begin(), cstr.end()); | |
if (s.size() % 2 == 0) { | |
cstr.erase(0, 1); | |
ret += cstr; | |
} | |
else{ | |
ret += cstr; | |
} | |
output(ret, 0); | |
return 0; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment