https://www.acmicpc.net/problem/2231
#include <iostream>
#include <string>
using namespace std;
int main(void) {
// C++ Init
ios::sync_with_stdio(false);
cin.tie(NULL);
int in1;
int num;
cin >> in1;
for (int i = 1; i <= 1000000; i++) {
string str = to_string(i);
int len = str.length();
num = 0;
for (int j = 0; j < len; j++) {
num += str[j] - '0';
}
if (i + num == in1) {
cout << i;
return 0;
}
}
cout << 0;
}
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 1712 손익분기점 (0) | 2024.12.15 |
---|---|
C++ 알고리즘 - 백준 1874 스택 수열 (0) | 2024.12.15 |
C++ 알고리즘 - 백준 30802 웰컴 키트 (0) | 2024.12.15 |
C++ 알고리즘 - 백준 10809 알파벳 찾기 (0) | 2024.12.14 |
C++ 알고리즘 - 백준 3052 나머지 (0) | 2024.12.14 |