알고리즘 문제/BOJ
6679번 싱기한 네자리 숫자
parkit
2018. 12. 3. 17:11
728x90
반응형
https://www.acmicpc.net/problem/6679
글제목은 오타 아닙니다.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #include <iostream> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> using namespace std; bool visit[10001] = { false, }; int twelve(int n) { int ret = 0; while (n != 0) { ret += n % 12; n /= 12; } return ret; } int sixteen(int n) { int ret = 0; while (n != 0) { ret += n % 16; n /= 16; } return ret; } void four() { for (int i = 2992; i < 10000; i++) { int one = i % 10; int ten = (i / 10) % 10; int hun = (i / 100) % 10; int tho = (i / 1000) % 10; int sum = one + ten + hun + tho; if (sum == twelve(i) && sum == sixteen(i)) { visit[i] = true; } } } int main(void) { four(); for (int i = 2992; i < 10000; i++) { if (visit[i]) printf("%d\n", i); } return 0; } | cs |
728x90
반응형