https://www.acmicpc.net/problem/2108
from collections import Counter
import sys
input = sys.stdin.readline
N = int(input())
heap = []
for _ in range(N):
num = int(input())
heap.append(num)
heap.sort()
print(round(sum(heap)/N)) # 산술 평균
print(heap[N//2]) # 중앙값
dic = Counter(heap)
sorted_items = sorted(dic.items(), key=lambda x: (-x[1], x[0])) # 값 기준 내림차순, 값 같으면 키 기준 오름차순
if len(sorted_items) >= 2 and sorted_items[0][1] == sorted_items[1][1]:
print(sorted_items[1][0]) # 두 번째로 작은 최빈값
else:
print(sorted_items[0][0]) # 최빈값
print(heap[-1]-heap[0]) # 범위'코딩테스트 > 코딩테스트 문제풀이' 카테고리의 다른 글
| [Python] 백준 <14889-스타트와 링크> (0) | 2025.05.28 |
|---|---|
| [Python] 백준 <2012-등수 매기기> (0) | 2025.05.27 |
| [Python] 백준 <18870-좌표 압축> (0) | 2025.05.21 |
| [Python] 백준 <10814-나이순 정렬> (0) | 2025.05.21 |
| [Python] 백준 <11000-강의실 배정> (0) | 2025.05.20 |