알고리즘 문제/BOJ
4673번 셀프 넘버
parkit
2018. 10. 11. 21:53
728x90
반응형
기본적인 구현 문제다.
문제 그대로 구현하면 된다.
https://www.acmicpc.net/problem/4673
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 | #include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <string.h> int num[10001] = { -1, }; void selfNumber() { for (int i = 1; i < 10000; i++) { if (i < 10) { int next = 2 * i; if (next <= 10000) num[next] = 1; } else if (i < 100) { int ten = i / 10; int one = i % 10; int next = i + ten + one; if (next <= 10000) num[next] = 1; } else if (i < 1000) { int hundred = i / 100; int ten = (i % 100) / 10; int one = i % 10; int next = i + hundred + ten + one; if (next <= 10000) num[next] = 1; } else { int thousand = i / 1000; int hundred = (i % 1000) / 100; int ten = (i % 100) / 10; int one = i % 10; int next = i + thousand + hundred + ten + one; if (next <= 10000) num[next] = 1; } } } int main(void) { memset(num, -1, sizeof(num)); selfNumber(); for (int i = 1; i <= 10000; i++) { if (num[i] == -1) printf("%d\n", i); } return 0; } | cs |
728x90
반응형