study gomi

[백준/baekjoon] 25206번 너의 평점은 python(파이썬) 본문

Practice/Baekjoon

[백준/baekjoon] 25206번 너의 평점은 python(파이썬)

공부하곰 2023. 12. 28. 18:37
728x90
반응형

내 제출

# 등급에 따른 과목평점, 등급이 P인 과목은 계산에서 제외
grade_table = {'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}

# (학점 * 과목 평점)의 합
score_sum = 0.0
# 학점의 총합
grade_sum = 0.0

# 20줄에 걸쳐 과목명, 학점, 등급이 공백으로 구분되어 주어짐
for _ in range(20):
    # 예_OperatingSystem 3.0 B0
    tmp = input().split()
    # 전공 평점은 학점 * 과목평점
    if tmp[2] in grade_table:
        grade_sum += float(tmp[1])
        score_sum += float(tmp[1]) * grade_table[tmp[2]]

# 전공평점은 전공과목별 (학점 * 과목평점)의 합을 학점의 총합으로 나눈 값
result = score_sum / grade_sum
print(result)

 

결과

 

원본 문제

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

 

굳이 dictionary를 쓰는 게 맞나 싶어서 다른 풀이를 찾아봤다.

https://calkolab.tistory.com/entry/baekjoon-python-25206

 

백준 BAEKJOON 25206번 너의 평점은 [PYTHON/파이썬]

백준 BAEKJOON 25206번 너의 평점은 [PYTHON/파이썬] https://www.acmicpc.net/problem/25206 25206번: 너의 평점은 인하대학교 컴퓨터공학과를 졸업하기 위해서는, 전공평점이 3.3 이상이거나 졸업고사를 통과해야

calkolab.tistory.com

이게 더 나은 것 같다.

728x90
반응형