Written by
java-style
on
on
[알고리즘/백준] 2231 분해합(자바)
[알고리즘/백준] 2231 분해합(자바)
문제
https://www.acmicpc.net/problem/2231
풀이 코드
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; 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()); for (int i = 1; i < n; i++) { int sum = i; //분해합 int temp = i; //각 자리수를 분해해서 더한다 while (temp != 0) { sum += temp%10; temp = temp/10; } if (sum == n) { System.out.println(i); return; } } //생성자가 없을 경우 0출력 System.out.println(0); } }
728x90
from http://developer-hm.tistory.com/167 by ccl(A) rewrite - 2021-09-26 00:01:35