본문 바로가기
알고리즘/일반(단순구현)

[백준] 1065번 한수 #Java

by VIPeveloper 2022. 5. 31.
반응형
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    static int N;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        N = Integer.parseInt(br.readLine());
        int cnt = 0;
        while (N > 0){
            cnt += solution(N);
            N--;
        }
        System.out.println(cnt);
    }

    private static int solution(int n) {
        if(n<100) return 1;
        if(100<= n && n < 1000){
            int a = String.valueOf(n).charAt(0);
            int b = String.valueOf(n).charAt(1);
            int c = String.valueOf(n).charAt(2);
            if((a-b) == (b-c)){
                return 1;
            }else{
                return 0;
            }
        }
        return 0;
    }
}
반응형