Skip to content

Instantly share code, notes, and snippets.

@ctylim
Created September 30, 2015 17:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ctylim/898ceeb027bce84185f7 to your computer and use it in GitHub Desktop.
yukicoder No.238
#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