結果

問題 No.238 Mr. K's Another Gift
ユーザー pekempey
提出日時 2015-07-05 23:28:11
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,080 bytes
コンパイル時間 1,483 ms
コンパイル使用メモリ 160,516 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-07 23:55:05
合計ジャッジ時間 3,146 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 u = s[s.length() - 1] + s;

    t.insert(pos, string(1, t[t.length() - pos - 1]));

    if (pal(t)) {
        cout << t << endl;
    } else if (pal(u)) {
        cout << u << endl; 
    } else {
        cout << "NA" << endl;
    }
}
0