자바 백준 1065번 한수


풀이 : 2자리수 이하의 모든 값은 한수이다. 3자리수에서는 두 번째 자리의 수와 첫 번째 자리수의 차가 세 번째 자리의 수와 두 번째 자리수의 차와 같으면 한수로 정의한다. 


import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
int result =0;
for(int i=input; i>0; i--) {
String input_st = String.valueOf(i);
if(input_st.length()<=2) {
result+=1;
}else {
int sub = input_st.charAt(1)-input_st.charAt(0);
int sub2 =input_st.charAt(2)-input_st.charAt(1);
if(sub==sub2) {
result+=1;
}
}
}
System.out.println(result);
}
}
view raw test.java hosted with ❤ by GitHub

'백준 알고리즘 > JAVA' 카테고리의 다른 글

자바 백준 5585번 거스름돈  (0) 2018.09.02
자바 백준 7568번 덩치  (1) 2018.08.25
자바 백준 2231번 분해합  (0) 2018.08.23
자바 백준 2309번 일곱 난쟁이  (0) 2018.08.16
자바 백준 3653번 영화 수집  (0) 2018.08.14

+ Recent posts