結果

問題 No.238 Mr. K's Another Gift
ユーザー nanasilinanasili
提出日時 2015-10-07 18:24:42
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,338 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 74,932 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 01:55:11
合計ジャッジ時間 2,628 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

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) << 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