728x90
한 숫자에 대해 10진수, 12진수, 16진수에서
각 숫자의 자리수를 더했을 때 세 값이
같은 숫자를 전부 출력하는 문제입니다.
#include <iostream>
const int MAX = 9999;
const int MIN = 1000;
using namespace std;
int main(int argc, char const *argv[]) {
int ten, twe, hex;
for (int i = MIN; i <= MAX; i++) {
ten = 0;
twe = 0;
hex = 0;
for (int n = i; n > 0; n /= 10) {
ten += n % 10;
}
for (int n = i; n > 0; n /= 12) {
twe += n % 12;
}
for (int n = i; n > 0; n /= 16) {
hex += n % 16;
}
if (ten == twe && twe == hex) {
cout << i << "\n";
}
}
return 0;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 6321번 IBM 빼기 1 (0) | 2019.09.23 |
---|---|
[C++] 백준 6378번 디지털 루트 (0) | 2019.09.23 |
[C++] 백준 3460번 이진수 (0) | 2019.09.23 |
[C++] 백준 2845번 파티가 끝나고 난 뒤 (0) | 2019.09.22 |
[C++] 백준 11506번 占쏙옙 (0) | 2019.09.22 |