Java/Java 알고리즘

백준 10162번 전자레인지 JAVA 구현해보기

kimc 2022. 1. 31. 20:29

```

백준 10162번 전자레인지 JAVA 구현해보기

```

이번 글을 통해 배워갈 내용

  1.  백준 10162번 풀이

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

 

10162번: 전자레인지

3개의 시간조절용 버튼 A B C가 달린 전자레인지가 있다. 각 버튼마다 일정한 시간이 지정되어 있어 해당 버튼을 한번 누를 때마다 그 시간이 동작시간에 더해진다. 버튼 A, B, C에 지정된 시간은

www.acmicpc.net

 

백준 10162번 전자레인지는 

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

 

300초 타이머 A

60초 타이머 B

10초 타이머 C

 

가 있고

시간이 주어질 때

주어진 타이머의 배수들을 이용해서 만들 수 있으면

최소 타이머의 개수를 출력하고

만들수 없다면 -1을 출력하면 됩니다.

 


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

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


모듈러 연산을 사용해서

타이머로 나눠지는지 확인하는 방법으로 계산하였습니다.

 

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

public class Main {

    static final int BUTTON_A_TIME = 300;
    static final int BUTTON_B_TIME = 60;
    static final int BUTTON_C_TIME = 10;

    public static void main(String[] args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        printMinButtonPress(Integer.parseInt(br.readLine()));
    }

    private static void printMinButtonPress(int cookingTime) {
        int buttonAPressCount = 0;
        int buttonBPressCount = 0;
        int buttonCPressCount;

        if (cookingTime % BUTTON_C_TIME != 0) {
            System.out.print(-1);
            return;
        }

        if (cookingTime % BUTTON_A_TIME >= 0) {
            buttonAPressCount = cookingTime / BUTTON_A_TIME;
            cookingTime = cookingTime % BUTTON_A_TIME;
        }

        if (cookingTime % BUTTON_B_TIME >= 0) {
            buttonBPressCount = cookingTime / BUTTON_B_TIME;
            cookingTime = cookingTime % BUTTON_B_TIME;
        }

        buttonCPressCount = cookingTime / BUTTON_C_TIME;

        System.out.print(
                buttonAPressCount + " " + buttonBPressCount + " " + buttonCPressCount
        );
    }
}

 

 

 

읽어주셔서 감사합니다

 

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

 

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

 


 

728x90