結果

問題 No.238 Mr. K's Another Gift
ユーザー masa
提出日時 2015-07-06 00:44:54
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 729 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 62,268 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 01:15:09
合計ジャッジ時間 2,507 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	string s, r, s1, r1;

	cin >> s;
	r = s;
	reverse(r.begin(), r.end());

	int n = s.size();
	if (s == r) {
		int idx = (s.size() - 1) / 2;
		s.insert(idx + 1, 1, s[idx]);
		cout << s << endl;
		return 0;
	}

	for (int i = 0; i <= n / 2; i++) {
		if (s[i] != r[i]) {
			char si = s[i];
			s.insert(i, 1, r[i]);
			r.insert(i, 1, si);
			break;
		}
	}

	string sr = s;
	string rr = r;
	reverse(sr.begin(), sr.end());
	reverse(rr.begin(), rr.end());

	if (s == sr) {
		cout << s << endl;
	} else if (r == rr) {
		cout << r << endl;
	} else {
		cout << "NA" << endl;
	}
	return 0;
}
0