오락기/codeWar

백준4673

문방구앞오락기 2017. 12. 29. 14:05

셀프넘버

예를 들어, 33으로 시작한다면 다음 수는 33 + 3 + 3 = 39이고, 그 다음 수는 39 + 3 + 9 = 51, 다음 수는 51 + 5 + 1 = 57이다. 이런식으로 다음과 같은 수열을 만들 수 있다.

33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ...

10000이하 



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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package B;
 
import java.util.*;
 
public class b1 {
 
    public static void main(String[] args) {
        
        String num ="";
        int sum =0;
        int cnt = 10000;
        int[] arr = new int[cnt];
        for(int i = 1 ; i <= cnt ; i++){
            
            
            num = String.valueOf(i) ;
            
            if(num.length() == 1){
                
                num = "0"+num;
                
            }
            
                for(int j = 0 ; j<num.length() ; j++){
                    
                    
                    sum+= Integer.parseInt(num.charAt(j)+"");
                }
                sum += Integer.parseInt(num);
                arr[i-1]= sum;
                sum=0;
        }
        
        Arrays.sort(arr);
        int a=1;
        boolean tf = true;
        
        for(int i = 1 ; i<cnt ; i++){
            tf = true;
            for(int  j = 0 ; j< arr.length ; j++){
                
                
                if(i == arr[j]){
                    tf = false;
                }
                
                if(i < arr[j]){
                    break;
                }
            }
            
            if(tf){
                System.out.println(i);
            }
    
            
            
        }
        
        
        
    }
            
    
}