백준 Bridž

KIMYEONGJUN·2026년 2월 9일
post-thumbnail

문제

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

The first line of input contains the integer N (1 ≤ N ≤ 10 000) from the task.
Each of the following N lines contains Ki , a string consisting of characters ‘A’, ‘K’, ‘Q’, ‘J’, ‘X’, of length 13, representing the cards Mirko had in his hand after dealing them for the ith time.

The first and only line of output must contain the required sum from the task.
SAMPLE TES

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

BufferedReader를 사용해 입력을 빠르게 받았다.
첫 번째 줄에서 N을 읽고, N번 반복하며 카드 문자열을 받는다.
각 13자리 문자열에서 한 글자씩 확인하며 점수를 계산한다.
카드 문자를 switch문으로 분기하여 A는 4점, K는 3점, Q는 2점, J는 1점, 그 외(X)는 0점으로 처리한다.
각 라운드 별 점수를 누적하여 totalPoints에 더한다.
마지막에 totalPoints를 출력한다.
모든 처리가 끝나고 br.close()로 리소스도 안전하게 닫는다.

코드로 구현

package baekjoon.baekjoon_32;

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

// 백준 14209번 문제
public class Main1293 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine()); // 카드 덱 개수
        int totalPoints = 0;

        for (int i = 0; i < N; i++) {
            String cards = br.readLine();
            int roundPoints = 0;
            for (int j = 0; j < 13; j++) {
                char card = cards.charAt(j);
                switch (card) {
                    case 'A':
                        roundPoints += 4;
                        break;
                    case 'K':
                        roundPoints += 3;
                        break;
                    case 'Q':
                        roundPoints += 2;
                        break;
                    case 'J':
                        roundPoints += 1;
                        break;
                    default:
                        // X 또는 다른 문자는 0점, 아무 처리 필요 없음
                        break;
                }
            }
            totalPoints += roundPoints;
        }

        System.out.println(totalPoints);
        br.close();
    }
}

마무리

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

profile
Junior backend developer

0개의 댓글