結果
| 問題 | 
                            No.238 Mr. K's Another Gift
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-07-05 23:41:26 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 4 ms / 2,000 ms | 
| コード長 | 1,164 bytes | 
| コンパイル時間 | 1,525 ms | 
| コンパイル使用メモリ | 160,624 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-08 00:57:49 | 
| 合計ジャッジ時間 | 2,637 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 40 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
bool pal(string s) {
    rep (i, s.length()) {
        if (s[i] != s[s.length() - i - 1]) {
            return false;
        }
    }
    return true;
}
int main() {
    string s;
    cin >> s;
    if (pal(s)) {
        if (s.length() % 2 == 0) {
            s.insert(s.length() / 2, "a");
        } else {
            s.insert(s.length() / 2, string(1, s[s.length() / 2]));
        }
        cout << s << endl;
        return 0;
    }
    string t = s;
    reverse(t.begin(), t.end());
    int pos = 0;
    rep (i, s.length()) {
        if (s[i] != t[i]) {
            pos = i;
            break;
        }
    }
    string ansA = t;
    string ansB = t;
    ansA.insert(pos, string(1, ansA[ansA.length() - pos - 1]));
    ansB.insert(ansB.length() - pos, string(1, ansB[pos]));
    if (pal(ansA)) {
        cout << ansA << endl;
    } else if (pal(ansB)) {
        cout << ansB << endl;
    } else {
        cout << "NA" << endl;
    }
}