달달한 스토리

728x90
반응형

 

정신없이 흘러간 일중리이다..

 

셀프 넘버를 풀다 어려워 답을 보고,

 

한수를 풀다가 어려워 답을 보고...

 

갑자기 난이도가 급 어려워진 느낌을 받았다.

 

자연스레 어려운 느낌을 받아 며칠간 코딩 테스틀 풀기가 꺼려지면서

 

도전하지 못하고 있다가,

 

너무 쉰 것 같아서 이어서 풀었다.

 

역시나.. 늦은 시간이라 답만 접어두려 한다.

 

4673

 

public class Test4673 {

    public static void main(String[] args) {

        boolean[] check = new boolean[10001];

        for (int i = 1; i < 10001; i++) {
            int self = getSelf(i);

            //true는 셀프넘버가 아닌 숫자이다.
            if (self < 10001)
                check[self] = true;

        }

        StringBuilder sb = new StringBuilder();

        //false인 값만 출렧한다.
        for (int i = 1; i < 10001; i++) {
            if (!check[i]) {
                sb.append(i).append('\n');
            }
        }

        System.out.print(sb);
    }


    //셀프넘버를 구한다. 1에서 10000까지 포함되지 않는 숫자가 셀프넘버이다.
    public static int getSelf(int num) {
        int total = num;
        while (num != 0) { //0이 될때 까지 돌린다.
            total += (num % 10);
            num /= 10;
        }
        return total;
    }

}

 

1065

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test1065 {
    public static void main(String[] args) throws IOException {
        //N이 주어졌을때 N보다 같거나 작은 한수의 개수를 출력하는 프로그램을 만든다.
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int count = 0;
        for (int i = 1; i <= N; i++) {
           if(i <= 99) {
               count++;
           }
           else {
               String[] numStr = Integer.toString(i).split("");
               if((parseInt(numStr[1]) - parseInt(numStr[0])) == (parseInt(numStr[2]) - parseInt(numStr[1])))
                   count++;
           }
        }
        System.out.println(count);
    }

    private static int parseInt(String str) {
        return Integer.parseInt(str);
    }

}

 

11654

 

public class Test11654 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int alpha = br.readLine().charAt(0);
        System.out.println(alpha);
    }
}

 

728x90
반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading