結果

問題 No.238 Mr. K's Another Gift
ユーザー alpha_virginisalpha_virginis
提出日時 2015-07-05 23:10:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,270 bytes
コンパイル時間 1,236 ms
コンパイル使用メモリ 148,468 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 07:12:34
合計ジャッジ時間 5,176 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 6 ms
4,380 KB
testcase_29 WA -
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 6 ms
4,380 KB
testcase_36 AC 6 ms
4,376 KB
testcase_37 AC 6 ms
4,380 KB
testcase_38 AC 6 ms
4,380 KB
testcase_39 AC 6 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:9: warning: ‘p’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   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::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