BOJ 2231 분해합

1 개요[ | ]

BOJ 2231 분해합


2 C++[ | ]

#include <iostream>
using namespace std;

int getDesum(int x) {
    int sum = x;
    while(x) {
        sum += x%10;
        x /= 10;
    }
    return sum;
}

int getCreator(int n) {
    for(int i=1; i<=n; i++) {
        if( getDesum(i) == n ) return i;
    }
    return 0;
}

int main() {
    int N;
    cin >> N;
    cout << getCreator(N) << '\n';
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}