본문 바로가기

Coding/백준 온라인 저지 (Baekjoon Online Judge)

백준 온라인 저지(Baekjoon Online Judge) - 25206 : 너의 평점은

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

 

25206번: 너의 평점은

인하대학교 컴퓨터공학과를 졸업하기 위해서는, 전공평점이 3.3 이상이거나 졸업고사를 통과해야 한다. 그런데 아뿔싸, 치훈이는 깜빡하고 졸업고사를 응시하지 않았다는 사실을 깨달았다! 치

www.acmicpc.net

 

#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
    map<string, double> grade_map = {
        {"A+", 4.5},
        {"A0", 4.0},
        {"B+", 3.5},
        {"B0", 3.0},
        {"C+", 2.5},
        {"C0", 2.0},
        {"D+", 1.5},
        {"D0", 1.0},
        {"F", 0.0},
        {"P", -1.0}
    };
    int num_subjects = 0;
    double total_score = 0.0;
    double total_credit = 0.0;
    while (true) {
        string subject_name;
        double credit;
        string grade;
        cin >> subject_name;
        if (cin.eof()) {
            break;
        }
        cin >> credit >> grade;
        if (grade_map[grade] >= 0) {
            num_subjects++;
            total_score += credit * grade_map[grade];
            total_credit += credit;
        }
    }
    cout.precision(6);
    cout << fixed << (total_credit == 0.0 ? 0.0 : total_score / total_credit) << endl;
    return 0;
}