[PYTHON] 백준 4344 - 평균은 넘겠지

이또삐(이민혁)·2023년 4월 13일

CODINGTEST

목록 보기
13/96
post-thumbnail

성능 요약

메모리: 114328 KB, 시간: 120 ms

분류

수학, 사칙연산

문제 설명

대학생 새내기들의 90%는 자신이 반에서 평균은 넘는다고 생각한다. 당신은 그들에게 슬픈 진실을 알려줘야 한다.

입력

첫째 줄에는 테스트 케이스의 개수 C가 주어진다.

둘째 줄부터 각 테스트 케이스마다 학생의 수 N(1 ≤ N ≤ 1000, N은 정수)이 첫 수로 주어지고, 이어서 N명의 점수가 주어진다. 점수는 0보다 크거나 같고, 100보다 작거나 같은 정수이다.

출력

각 케이스마다 한 줄씩 평균을 넘는 학생들의 비율을 반올림하여 소수점 셋째 자리까지 출력한다.

#https://www.acmicpc.net/problem/4344
#평균은 넘겠지

import sys
input = sys.stdin.readline

# average = [0] * 1000

c = int(input())
for i in range(c):
    n = list(map(int, input().split()))
    people = n[0]
    score = n[1:]

    average = sum(score)/people
    
    stu_cnt = 0

    for j in range(len(score)):
        if score[j] > average:
            stu_cnt += 1
    
    sub_result = (stu_cnt/len(score))*100

    result = "{:.3f}%".format(sub_result)

    print(result)

# for i in range(len(score)):
#     if score[i] > average
#https://www.acmicpc.net/problem/4344
#평균은 넘겠지

import sys
input = sys.stdin.readline

c = int(input())

def fun(score, people):
    cnt = 0

    average = sum(score) / people

    for i in range(len(score)):
        if score[i] > average:
            cnt += 1
    
    sub_result = cnt / people * 100
    result = "{:.3f}%".format(sub_result)
    
    return print(result)

for i in range(c):
    n = list(map(int, input().split()))
    people = n[0]
    score = n[1:]
    fun(score, people)
    # print(people)
    # print(score)
profile
해보자! 게임 클라 개발자!

0개의 댓글