結果
| 問題 |
No.238 Mr. K's Another Gift
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-01 02:28:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,974 bytes |
| コンパイル時間 | 973 ms |
| コンパイル使用メモリ | 88,044 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 18:48:11 |
| 合計ジャッジ時間 | 2,446 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#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++;
}
else if (s[l] == s[r - 1]) {
C.push_back(s[r]);
check = true;
r--;
}
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;
}