-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1026.cpp
53 lines (43 loc) · 942 Bytes
/
1026.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long llu;
string decToBin(llu n) {
string s = "";
while (n > 0) {
s = char(n % 2 + '0') + s;
n /= 2;
}
return s;
}
string atualizaString(string s, llu tam){
while(s.size() < tam){
s = "0" + s;
}
return s;
}
llu somaBin(string n1, string n2){
llu soma = 0;
llu i;
bool lado = n1.size() > n2.size();
bool igual = n1.size() == n2.size();
if(lado){
n2 = atualizaString(n2, n1.size());
}else if(!igual){
n1 = atualizaString(n1, n2.size());
}
for (i = 0; i < n1.size() ; ++i) {
if (n1[i] != n2[i]) {
soma += pow(2, n1.size() - i - 1);
}
}
return soma;
}
int main(){
llu n, m;
while(cin >> n >> m){
string n1 = decToBin(n);
string n2 = decToBin(m);
cout << somaBin(n1, n2) << endl;
}
return 0;
}