코딩테스트

[python] 백준 18110번 : solved.ac

Alpaca_data_cloud 2024. 7. 9. 10:29

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

 

해당 문제를 풀었을 때 나의 경우 런타임에러와 오답이 많이 되었던 문제이다.

  • 런타임 에러 이유 : n == 0 일 경우 처리를 해주어야 함
  • 오답 이유 : round() 함수에 있다. 5의 경우 반올림 해주지 않는다. 5를 초과해야 반올림 해준다.

이름 해결하기 위해서 0.5 를 더하고 int 로 정수로 만들어 주면 된다.

 

import sys
input = sys.stdin.readline
n = int(input())
dic = dict()
arr = [int(input()) for _ in range(n)]
exce = int((n*0.15)+0.5)
arr.sort()

if n == 0:
    print(0)
else:
    print(int((sum(arr[exce : n - exce])/len(arr[exce : n - exce]))+0.5))