본문 바로가기

프로그래밍/백준

백준 acm 4673 - 셀프 넘버

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.Arrays;
import java.util.List;
 
public class Main {
    public static void main(String args[]) {
        d(10000);
    }
 
    static void d(int n) {
        int next;
        Integer[] intnum = new Integer[n+1];
        for (int i = 1; i <= n; i++) {
            next = i;
            String number = Integer.toString(next);
            for (int j = 0; j < number.length(); j++) {
                next += number.charAt(j) - '0';
            }
            if(next <= n) {
                intnum[i] = next;
            }
        }
        List<Integer> list = Arrays.asList(intnum);
        for (int i = 1; i < intnum.length; i++) {
            if(list.indexOf(i) == -1) {
                System.out.println(i);
            }
        }
    }
}
cs


'프로그래밍 > 백준' 카테고리의 다른 글