Little Jay

[C++] 백준 6679번 - 싱기한 네자리 숫자 본문

알고리즘/BOJ

[C++] 백준 6679번 - 싱기한 네자리 숫자

Jay, Lee 2022. 3. 20. 19:16

진법 계산을 요구하는 Brute Force 문제

 

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int numbers[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

bool check(int dec, int hex, int doz) {
	return (dec == hex && hex == doz);
}

int dozen_calc(int n) {
	int doz_num = 0;
	int temp = n;
	while (temp) {
		doz_num += numbers[temp % 12];
		temp /= 12;
	}
	return doz_num;
}


int hex_calc(int n) {
	int hex_num = 0;
	int temp = n;
	while (temp) {
		hex_num += numbers[temp % 16];
		temp /= 16;
	}
	return hex_num;
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	for (int i = 2992; i < 10000; i++) {
		int temp = i;
		int dec_num = 0;
		dec_num += temp / 1000;
		temp %= 1000;
		dec_num += temp / 100;
		temp %= 100;
		dec_num += temp / 10;
		temp %= 10;
		dec_num += temp;
		if (check(dec_num, hex_calc(i), dozen_calc(i))) cout << i << endl;
	}


	return 0;

}
Comments