카테고리 없음
백준 2108
ylab
2022. 8. 2. 23:15
https://www.acmicpc.net/problem/2108
2108번: 통계학
첫째 줄에 수의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 단, N은 홀수이다. 그 다음 N개의 줄에는 정수들이 주어진다. 입력되는 정수의 절댓값은 4,000을 넘지 않는다.
www.acmicpc.net
from collections import Counter
import sys
k=int(input())
d=[]
for i in range(k):
#인풋 리스트에 담기
a= int(sys.stdin.readline())
d.append(a)
a=d
#산술평균
print(int(round((sum(a)/len(a)),ndigits=0)))
#중앙값
#sort 후 중앙
b=sorted(a)
print(b[int((1+len(a))/2)-1])
#최빈값
#counter 사용
cnt=Counter(b).most_common()
if len(cnt) >1 and cnt[0][1]==cnt[1][1]:
print(cnt[1][0])
else:
print(cnt[0][0])
#범위
print(b[len(a)-1]-b[0])
그냥 input하면 시간초과 나와서 import sys 쓰긴 했는데
sys.stdin.readline()
음 input만 써서 못푸는지 고민해봐야겠다