1부터 입력값까지 모든 수를 분해하여 처음으로 조건이 만족하는 수가 분해합중 가장 작은 수가 된다. 없을경우 분해합의 결과는 입력값보다 큰 수가 되므로 0을 출력하면 된다.
https://www.acmicpc.net/problem/2231
#include <iostream>
using namespace std;
int main()
{
int n, result = 0;
cin >> n;
int i;
for(i = 1; i <= n; i++)
{
result = i;
int j = i;
for(; j > 0; j/=10){
result += j % 10;
}
if(result == n)
break;
}
if(result > n)
i = 0;
cout << i << endl;
}