CSE/baekjoon & swexpert
백준 4673 셀프넘버 ] 함수사용
언제나 변함없이
2019. 3. 28. 00:02
반응형
/*
* 1 = 2
* 2 = 4
* 3 = 6
* 4 = 8
* 5 = 10
* ...
* 10 = 11
* 11 = 13
* 13 = 17
* ...
* 5000 = 5005
* ...
* 9950 = 9973
* 9951 = 9974
* ...
* 9972 = 9999
*
* */
public class Main {
public static void main(String[] args){
int[] arr = new int[10000];//0으로 초기화
for(int i = 1; i <= 10000; i++)
if(dn(i)<10000) arr[dn(i)]++;
for(int i = 1; i < 10000; i++)
if(arr[i] == 0) System.out.println(i);
}
public static int dn(int n) {
String nStr = Integer.toString(n);
int result = n;
for(int i = 0; i < nStr.length(); i++)
result += Integer.parseInt(nStr.charAt(i)+"");
return result;
}
}
반응형