結果

問題 No.238 Mr. K's Another Gift
ユーザー ctyl_0ctyl_0
提出日時 2015-10-01 02:22:56
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 2,007 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 88,652 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-19 18:47:44
合計ジャッジ時間 4,973 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 26 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 += 2, r--;
            }
            else if (s[l] == s[r - 1]) {
                C.push_back(s[r]);
                check = true;
                l++, r -= 2;
            }
            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;
}
0