結果

問題 No.238 Mr. K's Another Gift
ユーザー alpha_virginis
提出日時 2015-07-05 23:13:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,608 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 163,948 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-07 23:47:49
合計ジャッジ時間 3,876 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:3: warning: ‘p’ may be used uninitialized [-Wmaybe-uninitialized]
   23 |   if( p > str.size()/2 ) {
      |   ^~

ソースコード

diff #

#include <bits/stdc++.h>

int main() {

  std::string str;
  std::string str2;

  int p;
  char c;

  std::cin >> str;
  str2 = str;
  std::reverse(str2.begin(), str2.end());
  int n = str.size();

  for(int i = 0; i < str.size(); ++i) {
    if( str[i] != str2[i] ) {
      p = i;
      break;
    }
  }

  if( p > str.size()/2 ) {
    if( str.size() % 2 == 0 ) {
      std::stringstream ss;
      for(int i = 0; i < n/2; ++i) {
	ss << str[i];
      }
      ss << 'a';
      for(int i = n/2; i < n; ++i) {
	ss << str[i];
      }
      str = ss.str();
      str2 = str;
      std::reverse(str2.begin(), str2.end());
      if( str == str2 ) {
	std::cout << str << std::endl;
      }
      else {
	std::cout << "NA" << std::endl;
      }
      return 0;
    }
    else {
      std::stringstream ss;
      for(int i = 0; i < n/2; ++i) {
	ss << str[i];
      }
      ss << str[n/2];
      for(int i = n/2; i < n; ++i) {
	ss << str[i];
      }
      str = ss.str();
      str2 = str;
      std::reverse(str2.begin(), str2.end());
      if( str == str2 ) {
	std::cout << str << std::endl;
      }
      else {
	std::cout << "NA" << std::endl;
      }
      return 0;
    }
  }

  if( p != 0 ) {
    c = str[str.size()-p-1];
  }
  else {
    p = n;
    c = str[0];
  }
    
  std::stringstream ss;
  for(int i = 0; i < p; ++i) {
    ss << str[i];
  }
  ss << c;
  for(int i = p; i < n; ++i) {
    ss << str[i];
  }
  str = ss.str();
  str2 = str;
  std::reverse(str2.begin(), str2.end());
  if( str == str2 ) {
    std::cout << str << std::endl;
  }
  else {
    std::cout << "NA" << std::endl;
  }
  
  return 0;
}
0