백준 - 한 수 ( 1065번, JAVA )

changi123·2024년 12월 22일
1
post-thumbnail

math ( https://www.acmicpc.net/problem/1065 )

풀이

  • 문제에서 1000보다 작은수라 했으니 3자리의 각자리를 구해서 뒷수 - 앞수 ( 공차 ) 두개를 비교해서 같다면 같은 공차로된 수열
  • 이제 12월말🙄 열심히 달려보자
package problem_solving.math;

import java.util.Scanner;

public class BaekJoon_1065 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		
		int cnt = 0 ; 
		
		if( n < 100 ) {
			cnt = n ; 
			System.out.println(cnt);
			return ; 
		}
		
		
		cnt = 99 ; 
		for(int i= 100 ; i <= n ; i++) {
			int a = i / 100 ;
			int b = (i / 10) % 10 ;
			int c = i % 10 ; 
			
			if( (c-b) == (b-a)) {
				cnt++;
			}
		}
		
		System.out.println(cnt);
	}

}

profile
개발자 홍찬기 꾸준한 사람이 되자

0개의 댓글

관련 채용 정보