BOJ 4673 셀프 넘버

Jmnote (토론 | 기여)님의 2018년 7월 11일 (수) 21:12 판 (새 문서: 분류: BOJ 5단계 ==개요== * {{BOJ|4673}} ==Java== 분류: BOJ Java <source lang='Java'> public class Main { private static final int SIZE = 10000; private static...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

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