문제 : https://www.acmicpc.net/problem/6679
[알고리즘풀이]
1000 ~ 9999까지 10, 12, 16진수로 표현하면서 자릿수를 다 더해주고 같다면 출력, 아니라면 출력 X
#include<iostream>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int a, b, c, j ;
for (int i = 1000; i <= 9999; i++) {
a = 0, b = 0, c = 0;
j = i;
while (j != 0) {
a += j % 10;
j /= 10;
}
j = i;
while (j != 0) {
b += j % 12;
j /= 12;
}
j = i;
while (j != 0) {
c += j % 16;
j /= 16;
}
if (a == b && b == c)
cout << i << '\n';
}
return 0;
}
'Problem Solving > BOJ' 카테고리의 다른 글
[BOJ] 2075 : N번째 큰 수 - travelbeeee (0) | 2019.11.11 |
---|---|
[BOJ] 2023 : 신기한 소수 - travelbeeee (0) | 2019.11.06 |
[BOJ] 9372 : Flying Safely - travelbeeee (0) | 2019.11.06 |
[BOJ] 14490 : 백대열 - travelbeeee (0) | 2019.11.06 |
[BOJ] 2303 : 숫자 게임 - travelbeeee (0) | 2019.11.06 |