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
30
31
32
33
34
35
 
public class Main {
    
    public static void main(String[] args) throws Exception{
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        boolean[] check = new boolean[10000];
        
        for(int i = 0; i < 10000; i++) {
            check[number(i)] = true;
        }
        
        for(int i = 0; i < 10000; i++) {
            if(!check[i]) bw.write(i + "\n");
        }
        bw.flush();
    }
    
    public static int number(int i) {
        
        int n = i;
        int ans = n;
        while(n > 0) {
            ans += n % 10;
            n /= 10;
        }
        if(ans > 9999return 9999;
        return ans;
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

불리언 배열을 10000크기만큼 지정을 해준다.

number메소드에서 ans를 리턴해주는데, ans는 기존 값+ 일, 십, 백 천짜리까지 더해준다. 

리턴된 값을 boolean배열 방의 위치로 선정해주고, 방을 트루값으로 변환.

boolean의 디폴트 값은 false이니까 false이방만 출력해주면 셀프 넘버입니다

'알고리즘' 카테고리의 다른 글

백준 7단계(11654)  (0) 2019.12.07
백준 6단계(1065)  (0) 2019.12.07
백준 6단계(15596)  (0) 2019.12.07
백준 5단계(4344)  (0) 2019.11.28
백준 5단계(8958)  (0) 2019.11.28

+ Recent posts