알고리즘/백준

[java] 백준 4673

henry.hong 2019. 11. 28. 16:25

 

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class P4673 {


    public static void main(String[] args) {

        final int loop = 10000;

        StringBuffer sb = new StringBuffer();


        int i = 0;
        List<Integer> list = new ArrayList<Integer>();
        while(true){
            int r = d(++i);
            if(i >= loop) break;
            list.add(r);
        }
        list.sort(Comparator.naturalOrder());

        for(int j = 1 ; j <= loop ; j++){
            if(!list.contains(j)){
                sb.append(j).append("\n");
            }
        }
        System.out.println(sb.toString());
    }

    public static int d(int n){

        int length = (int) Math.log10(n)+1;
        int sum = n;
        for(int i = 0 ; i < length; i++){
            sum += (int)(n/Math.pow(10,i)%10);
        }

        return sum;
    }
}