結果

問題 No.581 XOR
ユーザー ミドリムシミドリムシ
提出日時 2017-10-27 22:32:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 897 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 65,464 KB
実行使用メモリ 11,080 KB
最終ジャッジ日時 2024-05-01 16:28:47
合計ジャッジ時間 3,982 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

string to_binary(long bina){
    string ans = "";
    for(int i = 0; bina > 0; i++){
        ans = to_string(bina % 2) + ans;
        bina /= 2;
    }
    return ans;
}

long binary_to_num(string bina){
    long ans = 0;
    for(int i = 0; i < bina.size(); i++){
        ans += (bina[bina.size() - i - 1] - '0') * pow(2, i);
    }
    return ans;
}

int main(){
    long A, C;
    cin >> A >> C;
    string binaryA = to_binary(A), binaryC = to_binary(C), binaryB = "";
    for(int i = 0; i < binaryC.size() - binaryA.size(); i++){
        binaryA = "0" + binaryA;
    }
    for(int i = 0; i < binaryC.size(); i++){
        if(binaryA[i] == binaryC[i]){
            binaryB.push_back('0');        
        }else{
            binaryB.push_back('1');        
        }
    }
    cout << binary_to_num(binaryB) << endl;
}
0