結果

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

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
using namespace std;
string s;
string rev;
int main(){
cin >> s;
rev = s;
reverse(rev.begin(), rev.end());
if (s == rev){
if (s.size() % 2){
for (int i = 0; i < s.size(); i++){
cout << s[i];
if (i == s.size() / 2){
cout << s[i];
}
}
cout << endl;
return 0;
}
else{
for (int i = 0; i < s.size(); i++){
cout << s[i];
if (i == s.size() / 2-1){
cout << s[i];
}
}
cout << endl;
return 0;
}
}
else{
bool ok = false;
int i = 0;
int j = s.size()-1;
int ind = 0;
char so = 'a';
bool ng = false;
while (i < j){
if (s[i] != s[j]){
if (ok){
ng = true;
break;
}
ind = i;
j--;
so = s[j+1];
ok = true;
continue;
}
i++;
j--;
}
if (ng){
}
else{
for (int i = 0; i < s.size(); i++){
if (ind == i){
cout << so;
}
cout << s[i];
}
cout << endl;
return 0;
}
}
bool ok = false;
int i = 0;
int j = s.size() - 1;
int ind = 0;
char so = 'a';
bool ng = false;
while (i < j){
if (s[i] != s[j]){
if (ok){
ng = true;
break;
}
ind = j;
i++;
so = s[i-1];
ok = true;
continue;
}
i++;
j--;
}
if (ng){
puts("NA");
return 0;
}
for (int i = 0; i < s.size(); i++){
cout << s[i];
if (ind == i){
cout << so;
}
}
cout << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0