結果
問題 |
No.238 Mr. K's Another Gift
|
ユーザー |
|
提出日時 | 2015-07-05 23:49:46 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 898 bytes |
コンパイル時間 | 1,109 ms |
コンパイル使用メモリ | 159,840 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-08 01:02:37 |
合計ジャッジ時間 | 2,574 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; int pos = s.length() / 2; rep (i, s.length()) { if (s[i] != s[s.length() - i - 1]) { pos = i; break; } } string ansA = s; string ansB = s; 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; } }