Java/Java 알고리즘

백준 20233번 Bicycle JAVA 구현해보기

kimc 2022. 2. 12. 23:57

```

백준 20233번 Bicycle JAVA 구현해보기

```

이번 글을 통해 배워갈 내용

  1.  백준 20233번 풀이

https://www.acmicpc.net/problem/20233

 

20233번: Bicycle

The first four lines of the input contain integers $a$, $x$, $b$, and $y$ ($0 \leq a, x, b, y \leq 100$), each on a separate line. The last line contains a single integer $T$ ($1 \leq T \leq 1440$) --- the total time spent on a bicycle during each day.

www.acmicpc.net

 

백준 20233번은

난이도 브론즈 등급의 문제로서

 

한 달 21일 일하는 김 씨가 있고

김 씨가 자전거로 출퇴근한다고 가정할 때

 

A 회사의

월 기본료는 a, 

매일 첫 30분 대여는 무료

무료 초과분은 분당 x 원을 내야 하고

 

B 회사의

월 기본료는 b, 

매일 첫 45분 대여는 무료

무료 초과분은 분당 y 원을 내야 하고

 

김 씨가 매일 자전거로 출퇴근하는 경우

T분 출퇴근한다면

 

김 씨가 A 회사, B회사에 내야 하는 금액을 뽑아주면 됩니다.

 


30분 정도 위에 링크를 방문하셔서 풀어보시고

안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.


A 회사

B 회사의

 

가격정보를 입력받고

 

기본 금액 + (출퇴근 시간 - 무료시간) * 분당 금액 * 출퇴근하는 날의 수

를 곱해주면 됩니다.

 

출퇴근 시간보다 무료시간이 큰 경우 음수가 나올 수 있기 때문에

삼항 연산자로 출퇴근 시간에 따라 적은 경우 무료시간과 같게 만들어서 0 처리했습니다.

 

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

public class Main {
    static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {

        int a = Integer.parseInt(br.readLine());
        int x = Integer.parseInt(br.readLine());
        int b = Integer.parseInt(br.readLine());
        int y = Integer.parseInt(br.readLine());
        int T = Integer.parseInt(br.readLine());

        // the amount of money you would spend on the first option
        // (base price + (commute time - free time) * minute fee) * working days
        int firstOptionFee = a + ((T>30 ? T : 30)  - 30) * x * 21;

        // the amount of money you would spend on the second option
        // base price + (commute time - free time) * minute fee * working days
        int secondOptionFee = b + ((T>45 ? T : 45) - 45) * y * 21;

        System.out.print(firstOptionFee + " " + secondOptionFee);
    }
}

 

읽어주셔서 감사합니다

 

무엇인가 얻어가셨기를 바라며

 

오늘도 즐거운 코딩 하시길 바랍니다 ~ :)

 


 

728x90