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

잔글 (Jmnote님이 BOJ 4673번. 셀프 넘버 문서를 BOJ 4673 셀프 넘버 문서로 이동했습니다)
(차이 없음)

2018년 7월 13일 (금) 19:51 판

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 }}