https://www.acmicpc.net/problem/2231
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int n;
int m = 0;
int cnt = 0;
bool flag = false;
cin >> n;
int temp = n;
while (temp != 0) {
temp /= 10;
cnt++;
}
if (n == 1) {
m = 0;
}
else {
int a = n - (9 * (cnt - 1));
while (a<=n) {
int b = a;
int c = a;
for (int i = 0; i < cnt; i++) {
b += c % 10;
c /= 10;
}
if (b == n) {
m = a;
break;
}
a++;
}
}
cout << m;
return 0;
}
'algorithm > Brute force' 카테고리의 다른 글
[백준/7568] 덩치 (0) | 2020.03.31 |
---|---|
[백준/2798] 블랙잭 (0) | 2020.03.30 |
댓글