본문 바로가기

Programming/BaekJoon

[C++] 백준 4673번 : 셀프 넘버


https://www.acmicpc.net/problem/4673




#include <iostream>

using namespace std;

int main() {

int Self_Num[10001];

for (int i = 0; i < 10001; i++) 

Self_Num[i] = i;


int tmp, sum = 0;

for (int i = 0; i < 10001; i++)

{

sum = i;

tmp = i;

while (tmp != 0) {

sum = tmp % 10 + sum;

tmp = tmp / 10;

}

if(sum <=10000)

Self_Num[sum] = 0;

}


for (int i = 0; i < 10001; i++) 

if (Self_Num[i] != 0)

cout << i << "\n";

}