結果

問題 No.2323 Nafmo、A+Bをする
ユーザー shin3110shin3110
提出日時 2023-05-28 15:20:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,803 bytes
コンパイル時間 1,527 ms
コンパイル使用メモリ 167,364 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 11:58:07
合計ジャッジ時間 2,475 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*

              ∧∧∩ 
             ( ゚∀゚)/ キタ━━━━━━(゚∀゚)━━━━━━!!!!
            ⊂   ノ  ゆっくり見てってね!!!!!!!!
             (つ ノ
    o          (ノ
     \      ☆
             |      o
          (⌒ ⌒ヽ   /     ☆
    \  (´⌒  ⌒  ⌒ヾ   /
      ('⌒ ; ⌒   ::⌒  )
     (´     )     ::: ) /
  ☆─ (´⌒;:    ::⌒`) :;  )

*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define _GLIBCXX_DEBUG


// 文字列(2進数表記)→10進数
ll binaryToDecimal(const string& binary) {
    ll decimal = 0;
    ll power = 1;

    // 逆順に処理するため、文字列を反転させる
    string reversedBinary(binary.rbegin(), binary.rend());

    for (char bit : reversedBinary) {
        if (bit == '1') {
            decimal += power;
        }
        power *= 2;
    }

    return decimal;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s, t; cin >>s >> t;
    if(s > t) swap(s, t);
    while(s.size() < t.size()) {
        s = '0' + s;
    }
    string ans = "";
    rep(i, 0, s.size()) {
        if(s[i] == '1') {
            if(t[i] == '0')ans += '1';
            else ans += '0';
        } else {
            if(t[i] == '0') ans += '0';
            else ans += '1';
        }
    }
    cout << binaryToDecimal(ans) << endl;
}
0