Solution
import collections
import sys
from typing import List
def solution(nums: List[int]) -> List[int]:
answer = []
# 산술평균
answer.append(round(sum(nums) / len(nums)))
# 중앙값
answer.append(sorted(nums)[len(nums) // 2])
# 최빈값
counter = collections.Counter(nums)
order = counter.most_common()
max_frequency = order[0][1]
frequencies = []
for x in order:
if x[1] == max_frequency:
frequencies.append(x[0])
if len(frequencies) == 1:
answer.append(frequencies[0])
else:
answer.append(sorted(frequencies)[1])
# 범위
answer.append(max(nums) - min(nums))
return answer
def main() -> None:
N = int(sys.stdin.readline().rstrip())
nums = []
for _ in range(N):
nums.append(int(sys.stdin.readline().rstrip()))
print(*solution(nums), sep='\n')
if __name__ == '__main__':
main()
Leave a comment