09-17 16:42
Notice
Recent Posts
Recent Comments
반응형
관리 메뉴

BAN2ARU

[백준/Python] 4344번 : 평균은 넘겠지 본문

Coding Test/BaekJoon

[백준/Python] 4344번 : 평균은 넘겠지

밴나루 2023. 5. 24. 12:47
  • 문제

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

 

  • 풀이
import sys
input = sys.stdin.readline

c = int(input())

for _ in range(c) :
    score = list(map(int, input().split()))
    avg = sum(score[1:])/score[0]
    cnt = 0
    for i in score[1:] :
        if i > avg :
            cnt += 1
    print(f'{cnt/score[0]*100:.3f}%')
  1. 학생의 수와 점수를 list로 선언
  1. sum과 slicing을 통해 전체 점수를 구한 후 학생의 수(score[0])를 나누어주어 평균을 구함
  1. for문을 통해 각 점수에 대해 평균을 넘은 경우 cnt에 1을 더해줌
  1. 최종적으로 평균을 넘은 학생 / 학생의 수를 통해 전체 비율을 구해줌
  1. 이를 f-string 방식으로 print 해주고 .3f를 통해 소수점 셋째 자리까지 출력해줌
728x90
Comments