백준 2231: 분해합
2023. 1. 31. 21:45ㆍ개인공부/코딩테스트
2231번: 분해합
어떤 자연수 N이 있을 때, 그 자연수 N의 분해합은 N과 N을 이루는 각 자리수의 합을 의미한다. 어떤 자연수 M의 분해합이 N인 경우, M을 N의 생성자라 한다. 예를 들어, 245의 분해합은 256(=245+2+4+5)이
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
int Number;
cin >> Number;
for (int i = Number - 100; i < Number; ++i)
{
int Result = i;
string strNumber = std::to_string(i);
for (int j = 0; j < strNumber.size(); ++j)
{
Result += strNumber[j] - 48;
}
if (Result == Number)
{
cout << i;
return 0;
}
if (i == Number - 1)
{
cout << 0;
}
}
}
|
cs |
'개인공부 > 코딩테스트' 카테고리의 다른 글
백준 1620 : 나는야 포켓몬 마스터 이다솜 (0) | 2023.02.01 |
---|---|
백준 1436: 영화감독 숌 (0) | 2023.01.31 |
백준 2798: 블랙잭 (0) | 2023.01.31 |
백준 2108: 통계학 (0) | 2023.01.31 |
백준 10814: 나이순 정렬 (0) | 2023.01.30 |