<2108번>
✍️ 문제 풀이
💻 코드
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
nums = [int(input()) for _ in range(n)]
print(round(sum(nums)/len(nums)))
nums.sort()
print(nums[len(nums)//2])
counts = Counter(nums).most_common()
if len(counts)>1 and (counts[0][1] == counts[1][1]):
print(counts[1][0])
else:
print(counts[0][0])
print(max(nums)-min(nums))
👀 문제 풀면서
- 반올림
소수점 n번째 자리까지만 표현하고 반올림하고 싶을 때
round(실수, n)
import math
math.ceil()
math.floor()
math.trunc()
- collections 모듈의 Counter 클래스
from collections import Counter
sample = "hihello"
counter = Counter(sample)
print(counter)
>>> Counter({'h': 2, 'l': 2, 'i': 1, 'e': 1,
'o': 1})
counter = Counter(sample).most_common()
print(counter)
>>> [('h', 2), ('l', 2), ('i', 1), ('e', 1), ('o', 1)]
counter = Counter(sample).most_common(2)
print(counter)
>>> [('h', 2), ('l', 2)]