結果

問題 No.238 Mr. K's Another Gift
ユーザー nanasili
提出日時 2015-10-07 18:20:36
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,340 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 74,744 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-20 01:55:01
合計ジャッジ時間 2,791 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool ok = true;
  for (int i = 1, j = n-1; i < j; i++, j--) {
    if (s[i] != s[j]) {
      ok = false;
      break;
    }
  }
  if (ok) {
    std::cout << s+s[0] << std::endl;
    return 0;
  }
  ok = true;
  for (int i = 0, j = n-2; i < j; i++, j--) {
    if (s[i] != s[j]) {
      ok = false;
      break;
    }   
  }
  if (ok) {
    std::cout << s[n-1]+s << std::endl;
    return 0;
  }
  for (int i = 0, j = n-1; i < j; i++, j--) {
    if (s[i] != s[j]) {
      ok = true;
      for (int k = i+1, l = j; k < l; k++, l--) {
	if (s[k] != s[l]) {
	  ok = false;
	}
      }
      if (ok) {
	std::cout << s.substr(0, j+1)+s[i]+s.substr(j+1) << std::endl;
	return 0;
      }
      ok = true;
      for (int k = i, l = j-1; k < l; k++, l--) {
	if (s[k] != s[l]) {
	  ok = false;
	}
      }
      if (ok) {
	std::cout << s.substr(0, i)+s[j]+s.substr(i-1) << std::endl;
	return 0;
      }
      std::cout << "NA" << std::endl;
      return 0;
    }
  }
  std::cout << s.substr(0, n/2)+s[n/2]+s.substr(n/2) << std::endl;
}
0