Baekjoon - 2231

Tadap·2023년 9월 13일
0

Baekjoon

목록 보기
12/94
post-custom-banner

문제

Solved.ac class 2++

1차시도

public class Main {
	private static int answer = 0;
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		calculate(n);

		System.out.println(answer);
	}

	private static void calculate(int n) {
		for (int i = 1; i < n; i++) {
			int d = disassemble(i);
			if (d == n) {
				answer = i;
				break;
			}
		}
	}

	private static int disassemble(int m) {
		String s = String.valueOf(m);
		int digits = 0;
		String[] split = s.split("");
		for (String string : split) {
			digits += Integer.parseInt(string);
		}
		return m + digits;
	}
}

성공

post-custom-banner

0개의 댓글