백준 19583 java : 자료구조

magicdrill·2025년 6월 25일

백준 문제풀이

목록 보기
625/675

백준 19583 java : 자료구조

입력 종료 조건이 없으니 BufferedReader를 사용해야 한다.
map 자료구조를 사용해 참석자 아이디를 기준으로 출석여부를 갱신한다.

import java.io.*;
import java.util.*;

public class bj19583 {
    static String S, E, Q;
    static Map<String, Boolean> attendedName = new HashMap<>();

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

        inputData(br);
        System.out.println(findAnswer());
    }

    public static void inputData(BufferedReader br) throws IOException {
        StringTokenizer st = new StringTokenizer(br.readLine());
        S = st.nextToken();
        E = st.nextToken();
        Q = st.nextToken();

        String line;
        while ((line = br.readLine()) != null && !line.isEmpty()) {
            String[] temp = line.split(" ");
            String time = temp[0];
            String name = temp[1];

            if (time.compareTo(S) <= 0) {
                attendedName.put(name, false);
                System.out.println(name + " 참석 시작");
            } else if (time.compareTo(E) >= 0 && time.compareTo(Q) <= 0) {
                if (attendedName.containsKey(name)) {
                    System.out.println(name + " 출석 완료");
                    attendedName.put(name, true);
                }
            }
        }
    }

    public static int findAnswer() {
        int answer = 0;

        for (boolean val : attendedName.values()) {
            if (val) {
                answer++;
            }
        }
        return answer;
    }
}

0개의 댓글