ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 2108 |
문제명 | 통계학 |
레벨 | 실버 4 |
분류 |
기초 |
시간복잡도 | O(nlogn) |
인풋사이즈 | n<=500,000 |
사용한 언어 | Python |
제출기록 | 50552KB / 512ms |
최고기록 | 228ms |
해결날짜 | 2021/08/24 |
"""Solution code for "BOJ 2108. 통계학".
- Problem link: https://www.acmicpc.net/problem/2108
- Solution link: http://www.teferi.net/ps/problems/boj/2108
"""
import statistics
import sys
def main():
N = int(sys.stdin.readline())
nums = [int(sys.stdin.readline()) for _ in range(N)]
print(round(statistics.mean(nums)))
print(statistics.median(nums))
modes = statistics.multimode(nums)
if len(modes) == 1:
print(modes[0])
else:
print(sorted(modes)[1])
print(max(nums) - min(nums))
if __name__ == '__main__':
main()
"""Solution code for "BOJ 2108. 통계학".
- Problem link: https://www.acmicpc.net/problem/2108
- Solution link: http://www.teferi.net/ps/problems/boj/2108
"""
import itertools
import sys
def main():
N = int(sys.stdin.readline())
nums = [int(sys.stdin.readline()) for _ in range(N)]
nums.sort()
print(round(sum(nums) / N))
print(nums[N // 2])
mode, count, is_first = 0, 0, False
for k, g in itertools.groupby(nums):
l = len(list(g))
if l > count:
mode, count, is_first = k, l, True
elif l == count and is_first:
mode, count, is_first = k, l, False
print(mode)
print(nums[-1] - nums[0])
if __name__ == '__main__':
main()