Wednesday, 10 February 2016

Uva - 10469 - To Carry or not to Carry Problem Solution.


Solution:

#include<bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    unsigned int a,b;
    while(cin >> a >> b){
        bitset<32>ab(a),bb(b);
        unsigned int res = 0;
        for(int i = 0; i < 32;i++){
            if((ab[i] ^ bb[i]) == 1){
                res += pow(2,i);
            }
        }
        cout << res << endl;
    }
    return 0;
}

Another Way:

#include<bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int a,b;
    while(cin >> a >> b)cout << (a^b) << endl;
    return 0;
}

No comments:

Post a Comment