[Eric's 백준] 1712번 - 손익분기점 - Java

Eric·2023년 1월 17일
0

BoJ(백준)

목록 보기
4/6
post-thumbnail

백준 1712번 문제 손익분기점 입니다.

제가 하단과 같이 푼 이유는

만약 b값이 c보다 크거나 같으면

아무리 물건을 팔아도 이득이 나지 않기에

바로 -1 을 리턴하였고,

나머지 값들은

b -c 로 price 값을 구해서

a를 price 로 나누고 +1 을 진행 하였습니다.

그 이유는 a에서 price 로 나누었을때의 몫이

판매했을때의 손익분기점의 딱 이전 값이여서

이 몫에 1을 더해서 구하였습니다.

import java.util.Scanner;

public class N1712 {
    public static void main(String[] args) {
        N1712 T = new N1712();
        Scanner kb = new Scanner(System.in);
        int a = kb.nextInt();
        int b = kb.nextInt();
        int c = kb.nextInt();
        System.out.println(T.solution(a, b, c));
    }

    public int solution(int a, int b, int c){
        int answer = -1;
        if(b>=c){
            return answer;
        }else {
            int price = c - b;
            answer = a / price +1;
        }
        return answer;
    }
}
profile
Ærlighed i små ting er ikke nogen lille ting.

0개의 댓글