백준 Cupcake Party

KIMYEONGJUN·2025년 2월 4일
post-thumbnail

문제

내가 생각했을때 문제에서 원하는부분

The input consists of two lines.
The first line contains an integer R ≥ 0, representing the number of regular boxes.
The second line contains an integer S ≥ 0, representing the number of small boxes.

Output the number of cupcakes that are left over.

내가 이 문제를 보고 생각해본 부분

BufferedReader를 사용하여 입력을 받는다.
두 개의 정수를 입력 받아 각각 정규 박스와 소형 박스의 수를 저장한다.
총 컵케이크 수는 R * 8 + S * 3으로 계산한다.
28명의 학생에게 하나씩 나눠주고 남은 컵케이크의 수를 계산한다.
남은 컵케이크가 음수일 경우 0으로 설정한다.
최종적으로 남은 컵케이크의 수를 출력한다.

코드로 구현

package baekjoon.baekjoon_26;

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

// 백준 24568번 문제
public class Main923 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        // 입력 받기
        int R = Integer.parseInt(br.readLine()); // 정규 박스 수
        int S = Integer.parseInt(br.readLine()); // 소형 박스 수

        // 총 컵케이크 수 계산
        int totalCupcakes = R * 8 + S * 3;

        // 학생 수
        int students = 28;

        // 남은 컵케이크 계산
        int leftoverCupcakes = totalCupcakes - students;

        // 남은 컵케이크가 음수일 경우 0으로 설정
        if(leftoverCupcakes < 0) {
           leftoverCupcakes = 0;
        }

        // 결과 출력
        System.out.println(leftoverCupcakes);
        br.close();
    }
}

마무리

코드와 설명이 부족할수 있습니다. 코드를 보시고 문제가 있거나 코드 개선이 필요한 부분이 있다면 댓글로 말해주시면 감사한 마음으로 참고해 코드를 수정 하겠습니다.

profile
Junior backend developer

0개의 댓글