백준 11531 java : 구현

magicdrill·2025년 10월 6일

백준 문제풀이

목록 보기
656/673

백준 11531 java : 구현

import java.util.*;

public class BJ11531 {
    static class Log {
        int m;
        String problemName;
        String result;

        public Log(int m, String problemName, String result) {
            this.m = m;
            this.problemName = problemName;
            this.result = result;
        }
    }

    static ArrayList<Log> logs = new ArrayList<>();

    public static void main(String[] args) {
        inputData();
        findAnswer();
    }

    public static void inputData() {
        Scanner sc = new Scanner(System.in);

        while (true) {
            int m = sc.nextInt();
            if (m == -1) {
                break;
            }

            String problemName = sc.next();
            String result = sc.next();

            logs.add(new Log(m, problemName, result));
        }

        sc.close();
    }

    public static void findAnswer() {
        HashMap<String, Integer> wrongCount = new HashMap<>();
        HashSet<String> solved = new HashSet<>();
        int correct = 0, totalTime = 0;

        for (Log log : logs) {
            String name = log.problemName;

            if (solved.contains(name)) {
                continue;
            }

            if (log.result.equals("right")) {
                correct++;
                totalTime += log.m + wrongCount.getOrDefault(name, 0) * 20;
                solved.add(name);
            } else if (log.result.equals("wrong")) {
                wrongCount.put(name, wrongCount.getOrDefault(name, 0) + 1);
            }
        }

        System.out.println(correct + " " + totalTime);
    }
}

0개의 댓글