結果

問題 No.2323 Nafmo、A+Bをする
ユーザー shin3110shin3110
提出日時 2023-05-28 15:25:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,817 bytes
コンパイル時間 1,756 ms
コンパイル使用メモリ 169,736 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 06:38:55
合計ジャッジ時間 2,789 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 14 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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';
        }
    }
    ll z = binaryToDecimal(ans);
    cout << z << endl;
}
0