10진수 -> 2진수로 변경 후
carry 값을 0으로 만들어주면 끝나는 매우 쉬운 문제
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
54
55
56
|
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <cmath>
#include <limits>
#include <cstring>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long n1, n2;
int a[40], b[40];
while (1) {
cin >> n1 >> n2;
if (cin.eof()) break;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
// 10진수 -> 2진수
string astr = "", bstr = "";
while (n1) {
if (n1 == 1) {
astr += '1';
break;
}
astr += (n1 % 2) + '0';
n1 /= 2;
}
while (n2) {
if (n2 == 1) {
bstr += '1';
break;
}
bstr += (n2 % 2) + '0';
n2 /= 2;
}
for (int i = astr.size() - 1; i >= 0; i--) a[i] = astr[i] == '1' ? 1 : 0;
for (int i = bstr.size() - 1; i >= 0; i--) b[i] = bstr[i] == '1' ? 1 : 0;
int len = max(astr.size(), bstr.size());
long long ans = 0;
for (int i = 0; i < len; i++) {
if (a[i] && b[i]) continue;
if (a[i] || b[i]) ans += pow(2, i);
}
cout << ans << "\n";
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'algorithm > uva' 카테고리의 다른 글
uva 384번 Slurpys, BOJ 14906번 스러피 (0) | 2020.03.31 |
---|---|
uva 10150번 Doublets (0) | 2020.03.27 |
uva 10010번 Where's Waldorf? (0) | 2020.03.23 |
uva 679 - Dropping Balls (0) | 2020.03.19 |
uva 10137 - the trip, BOJ 4411번 (0) | 2020.03.19 |