๐Ÿ ํŒŒ์ด์ฌ ์ƒ์ดˆ์งœ

[BOJ][Python] ๋ฐฑ์ค€ 25206๋ฒˆ: ๋„ˆ์˜ ํ‰์ ์€

์„ ๋‹ฌ 2024. 10. 15. 01:46
๋ฐ˜์‘ํ˜•

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

 

๋ฌธ์ œ

์ธํ•˜๋Œ€ํ•™๊ต ์ปดํ“จํ„ฐ๊ณตํ•™๊ณผ๋ฅผ ์กธ์—…ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, ์ „๊ณตํ‰์ ์ด 3.3 ์ด์ƒ์ด๊ฑฐ๋‚˜ ์กธ์—…๊ณ ์‚ฌ๋ฅผ ํ†ต๊ณผํ•ด์•ผ ํ•œ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์•„๋ฟ”์‹ธ, ์น˜ํ›ˆ์ด๋Š” ๊นœ๋นกํ•˜๊ณ  ์กธ์—…๊ณ ์‚ฌ๋ฅผ ์‘์‹œํ•˜์ง€ ์•Š์•˜๋‹ค๋Š” ์‚ฌ์‹ค์„ ๊นจ๋‹ฌ์•˜๋‹ค!

์น˜ํ›ˆ์ด์˜ ์ „๊ณตํ‰์ ์„ ๊ณ„์‚ฐํ•ด์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์ž.

์ „๊ณตํ‰์ ์€ ์ „๊ณต๊ณผ๋ชฉ๋ณ„ (ํ•™์  × ๊ณผ๋ชฉํ‰์ )์˜ ํ•ฉ์„ ํ•™์ ์˜ ์ดํ•ฉ์œผ๋กœ ๋‚˜๋ˆˆ ๊ฐ’์ด๋‹ค.

์ธํ•˜๋Œ€ํ•™๊ต ์ปดํ“จํ„ฐ๊ณตํ•™๊ณผ์˜ ๋“ฑ๊ธ‰์— ๋”ฐ๋ฅธ ๊ณผ๋ชฉํ‰์ ์€ ๋‹ค์Œ ํ‘œ์™€ ๊ฐ™๋‹ค.

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/F ๊ณผ๋ชฉ์˜ ๊ฒฝ์šฐ ๋“ฑ๊ธ‰์ด P๋˜๋Š” F๋กœ ํ‘œ์‹œ๋˜๋Š”๋ฐ, ๋“ฑ๊ธ‰์ด P์ธ ๊ณผ๋ชฉ์€ ๊ณ„์‚ฐ์—์„œ ์ œ์™ธํ•ด์•ผ ํ•œ๋‹ค.

๊ณผ์—ฐ ์น˜ํ›ˆ์ด๋Š” ๋ฌด์‚ฌํžˆ ์กธ์—…ํ•  ์ˆ˜ ์žˆ์„๊นŒ?

์ž…๋ ฅ

20์ค„์— ๊ฑธ์ณ ์น˜ํ›ˆ์ด๊ฐ€ ์ˆ˜๊ฐ•ํ•œ ์ „๊ณต๊ณผ๋ชฉ์˜ ๊ณผ๋ชฉ๋ช…, ํ•™์ , ๋“ฑ๊ธ‰์ด ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด ์ฃผ์–ด์ง„๋‹ค.

์ถœ๋ ฅ

์น˜ํ›ˆ์ด์˜ ์ „๊ณตํ‰์ ์„ ์ถœ๋ ฅํ•œ๋‹ค.

์ •๋‹ต๊ณผ์˜ ์ ˆ๋Œ€์˜ค์ฐจ ๋˜๋Š” ์ƒ๋Œ€์˜ค์ฐจ๊ฐ€ 10−4 ์ดํ•˜์ด๋ฉด ์ •๋‹ต์œผ๋กœ ์ธ์ •ํ•œ๋‹ค.

ํ’€์ด

dic = {'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
credit_sum = 0

for _ in range(20):
    subject, credit, grade = map(str, input().split())
    credit = float(credit)
    
    if grade!='P':
        credit_sum += credit
        score_sum += dic[grade] * credit

avg_grade = score_sum/credit_sum if credit_sum!=0 else 0
print(avg_grade)
๋ฐ˜์‘ํ˜•