백준 2231

jaegeunsong97·2023년 3월 12일
0
post-thumbnail

브루트 포스 알고리즘이여서, 하나한 순회하면서 일일히 계산을 하면 된다. 간단하다!!

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        
        int answer = 0;
        for (int i = 0; i < N; i++) {
            int num = i;
            int sum = 0;
            
            while (num != 0) {
                sum += (num % 10);
                num /= 10;
            }
            
            if (sum + i == N) {
                answer = i;
                break;
            }
        }
        System.out.println(answer);
    }
}
profile
현재 블로그 : https://jasonsong97.tistory.com/

0개의 댓글