[문제 링크]

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


문자열을 이용하는간단한 구현 문제였다.

등급에 따른 과목평점을 Map 컨테이너에 담아서 간단하게 매칭시켰다.


#include <iostream>
#include <string>
#include <map>
using namespace std;

void gradeMapping(map<string, float>& gradeScoreMap) {
	gradeScoreMap["A+"] = 4.5f;
	gradeScoreMap["A0"] = 4.0f;
	gradeScoreMap["B+"] = 3.5f;
	gradeScoreMap["B0"] = 3.0f;
	gradeScoreMap["C+"] = 2.5f;
	gradeScoreMap["C0"] = 2.0f;
	gradeScoreMap["D+"] = 1.5f;
	gradeScoreMap["D0"] = 1.0f;
	gradeScoreMap["F"] = 0.0f;
}

int main(void) {
	map<string, float> gradeScoreMap;
	gradeMapping(gradeScoreMap);

	float credit = 0;
	float totalCredit = 0;

	for (int i = 0; i < 20; i++) {
		string subjectStr, creditStr, gradeStr;
		cin >> subjectStr >> creditStr >> gradeStr;
		if (gradeStr == "P")
			continue;
		else {
			float nowCredit = stof(creditStr);
			float nowGrade = gradeScoreMap[gradeStr];
			credit += nowCredit;
			totalCredit += nowCredit * nowGrade;
		}
	}

	cout << totalCredit / credit << endl;

	return 0;
}

'알고리즘 > BOJ' 카테고리의 다른 글

백준 7569번: 토마토  (0) 2023.08.18
백준 5430번: AC  (0) 2022.10.15
백준 1764번: 듣보잡  (0) 2022.10.15
백준 4963번: 섬의 개수  (0) 2022.10.15
백준 11724번: 연결 요소의 개수  (0) 2022.10.15

+ Recent posts