結果

問題 No.197 手品
ユーザー knkknk
提出日時 2017-09-18 14:41:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,078 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 70,816 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 03:53:28
合計ジャッジ時間 1,593 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:30:57: warning: 'idx_a' may be used uninitialized [-Wmaybe-uninitialized]
   30 |     std::cout << (idx_b != idx_a ? "SUCCESS" : "FAILURE") << std::endl;
      |                                                         ^
main.cpp:24:14: note: 'idx_a' was declared here
   24 |   int idx_b, idx_a;
      |              ^~~~~
main.cpp:30:57: warning: 'idx_b' may be used uninitialized [-Wmaybe-uninitialized]
   30 |     std::cout << (idx_b != idx_a ? "SUCCESS" : "FAILURE") << std::endl;
      |                                                         ^
main.cpp:24:7: note: 'idx_b' was declared here
   24 |   int idx_b, idx_a;
      |       ^~~~~

ソースコード

diff #

#include <iostream>
#include <iomanip>

typedef long long ll;

int main(void)
{
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(8);
  std::string s_bef;
  ll n;
  std::string s_aft;
  std::cin >> s_bef >> n >> s_aft;
  int cnt_b = 0, cnt_a = 0;
  for (int i = 0; i < 3; ++i) {
    if (s_bef[i]=='o') cnt_b++;
    if (s_aft[i]=='o') cnt_a++;
  }
  if (cnt_b != cnt_a) {std::cout << "SUCCESS" << std::endl; return 0;}
  if ((s_bef=="ooo" && s_aft=="ooo") || (s_bef=="xxx" && s_aft=="xxx")) {
    std::cout << "FAILURE" << std::endl; return 0;
  }
  int idx_b, idx_a;
  for (int i = 0; i < 3; ++i) {
    if (s_bef[i] == (cnt_b==1 ? 'o' : 'x')) idx_b = i;
    if (s_aft[i] == (cnt_b==1 ? 'o' : 'x')) idx_a = i;
  }
  if (n==0) {
    std::cout << (idx_b != idx_a ? "SUCCESS" : "FAILURE") << std::endl;
    return 0;
  }
  if (n==1) {
    if (idx_b==1 && idx_b==idx_a) {
      std::cout << "SUCCESS" << std::endl;
      return 0;
    }
  }
  std::cout << (abs(idx_b-idx_a) > n ? "SUCCESS" : "FAILURE") << std::endl;
  return 0;
}
0