끄적끄적 코딩
article thumbnail

한 숫자에 대해 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;
}

검색 태그