본문 바로가기

Coding Test

백준 4344번 - 리스트, %.nf

슬픈진실은 나를 비껴간적이 없어..

○ 예제 입력

5
5 50 50 70 80 100
7 100 95 90 80 70 60 50
3 70 90 80
3 70 90 81
9 100 99 98 97 96 95 94 93 91

예제 출력

40.000%
57.143%
33.333%
66.667%
55.556%

● 답안

C = int(input())

for i in range(C):
    case = list(map(int, input().split()))
    avg = sum(case[1:])/case[0]
    cnt = 0 
    for i in range(1, len(case)):
        if case[i] > avg:
            cnt += 1
    print('%.3f'%(cnt/case[0]*100)+'%')

◎ 참고 : 서식문자 %.nf

N = float(input())

print('%.1f' % N) # 소수점 첫째자리까지만
print('%.2f' % N) # 소수점 둘째자리까지만
print('%.3f' % N) # 소수점 셋째자리까지만

print('%10.nf' % N) # 빈칸 10개, n자리까지

print('%010.nf' % N) # 빈칸을 0으로 채우고 n자리까지

 

 

'Coding Test' 카테고리의 다른 글

백준 1065번 - list  (0) 2022.03.05
백준 4673번 - set  (0) 2022.03.04
백준 2884번, 2525번 - if문  (0) 2022.02.23
백준 1110번 - while문  (0) 2022.02.19
백준 10951번 - while문 탈출  (0) 2022.02.18