카테고리 없음

[백준2231 JAVA] 분해합

그릿GRIT 2021. 5. 19. 09:44
728x90

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
    
	static int result;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		List<Integer> constlist = new ArrayList<Integer>();
		for(int i = 0 ; i<number; i++) {
			int j = i;
			int k = i;
			while(j!=0) {
				k += j%10;
				j /= 10;
			}
			if(k==number) constlist.add(i);
		}
		for(Integer c:constlist) {
			if(c <= constlist.get(0)) {
				result = c;
			} 
		}
		System.out.println(result);
	}
}