Last active
July 24, 2019 16:18
-
-
Save glowing713/67680e156acc5dc6add85306f1490837 to your computer and use it in GitHub Desktop.
백준 4673번 셀프 넘버
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MAX 10001 | |
#include <iostream> | |
using namespace std; | |
int d(int n); // n과 n의 각 자리수 더하는 함수 | |
int main(void){ | |
int arr[MAX] = {0,}; // 크기가 10001인 배열을 0으로 초기화 | |
/***************** 모든 생성자를 1로 설정 *****************/ | |
for(int i = 1; i < MAX; i++){ | |
int temp = d(i); | |
if(temp <= MAX){ | |
arr[temp] = 1; | |
} | |
} | |
/*****************************************************/ | |
for(int j = 1; j < MAX; j++){ | |
if(arr[j] == 0) cout << j << endl; | |
} | |
return 0; | |
} | |
int d(int n){ // n과 n의 각 자리수 더하는 함수 | |
int result = n; | |
while(n != 0){ | |
result += n % 10; | |
n /= 10; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment