"BOJ 4673 셀프 넘버"의 두 판 사이의 차이

(새 문서: 분류: BOJ 5단계 ==개요== * {{BOJ|4673}} ==Java== 분류: BOJ Java <source lang='Java'> public class Main { private static final int SIZE = 10000; private static...)
 
30번째 줄: 30번째 줄:
==같이 보기==
==같이 보기==
* [[셀프 넘버]]
* [[셀프 넘버]]
* [[에라토스테네스의 체]]

2018년 7월 11일 (수) 21:13 판

1 개요

BOJ 4673 셀프 넘버

[[분류:BOJ {{{단계}}}단계]]


2 Java

public class Main {
    private static final int SIZE = 10000;
    private static boolean[] flags = new boolean[SIZE+1];
    private static int d(int n) {
        int result = n;
        char[] digits = String.valueOf(n).toCharArray();
        for( int i=0; i<digits.length; i++ ) {
            result += digits[i] - '0';
        }
        return result;
    }
    public static void main(String args[]) {
        int temp;
        for(int i=1; i<=SIZE; i++) {
            if( !flags[i] ) System.out.println(i);
            temp = d(i);
            if( temp <= SIZE ) flags[temp] = true;
        }
    }
}

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}