結果
| 問題 | 
                            No.238 Mr. K's Another Gift
                             | 
                    
| コンテスト | |
| ユーザー | 
                             alpha_virginis
                         | 
                    
| 提出日時 | 2015-07-05 23:10:48 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,270 bytes | 
| コンパイル時間 | 1,655 ms | 
| コンパイル使用メモリ | 161,756 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-07 23:47:21 | 
| 合計ジャッジ時間 | 3,745 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 31 WA * 9 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:3: warning: ‘p’ may be used uninitialized [-Wmaybe-uninitialized]
   23 |   if( p > str.size()/2 ) {
      |   ^~
            
            ソースコード
#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;
}
            
            
            
        
            
alpha_virginis