백준

백준 2108번: 통계학

2호0 2021. 5. 18. 01:44

2108번: 통계학 (acmicpc.net)

 

2108번: 통계학

첫째 줄에 수의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 단, N은 홀수이다. 그 다음 N개의 줄에는 정수들이 주어진다. 입력되는 정수의 절댓값은 4,000을 넘지 않는다.

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from collections import Counter
import sys
= int(input())
math = []
for i in range(n):
    math.append(int(sys.stdin.readline()))
math.sort()
most = Counter(math)
result = most.most_common(2)
 
print(round(sum(math)/n))
print(math[int(len(math)/2)])
if len(result)==1:
    print(result[0][0])
elif result[0][1]==result[1][1]:
    print(result[1][0])
else:
    print(result[0][0])
 
print(math[-1]-math[0])
 
cs