기술 블로그

2231번 분해합 본문

알고리즘 문제/BOJ

2231번 분해합

parkit 2018. 12. 18. 10:14
728x90
반응형

https://www.acmicpc.net/problem/2231


시간초과 뜰 줄 알았는데 안 떴다.


1이상 100만이하 모든 수를 탐색할 수 밖에 없는 문제인 것 같다.



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
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
 
using namespace std;
 
int MIN = INT32_MAX;
 
void DivideSum(int N)
{
    for (int i = 1; i <= 1000000; i++)
    {
        string str = to_string(i);
 
        int sum = i;
 
        for (int j = 0; j < str.length(); j++)
            sum += str[j] - '0';
 
        if (sum == N) MIN = min(MIN, i);
    }
}
 
int main(void)
{
    int N = 0;
 
    scanf("%d"&N);
 
    DivideSum(N);
 
    if(MIN != INT32_MAX) printf("%d\n", MIN);
    else printf("0\n");
 
    return 0;
}
cs


728x90
반응형

'알고리즘 문제 > BOJ' 카테고리의 다른 글

5567번 결혼식  (0) 2018.12.24
9372번 상근이의 여행  (0) 2018.12.19
1065번 한수  (0) 2018.12.18
2161번 카드1  (0) 2018.12.15
1018번 체스판 다시 칠하기  (0) 2018.12.14