๐Ÿค–/๋ฐฑ์ค€

๋ฐฑ์ค€ 2108: ํ†ต๊ณ„ํ•™ (Python)

sssbin 2021. 9. 13. 15:43

https://www.acmicpc.net/problem/2108

 

2108๋ฒˆ: ํ†ต๊ณ„ํ•™

์ฒซ์งธ ์ค„์— ์ˆ˜์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 500,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹จ, N์€ ํ™€์ˆ˜์ด๋‹ค. ๊ทธ ๋‹ค์Œ N๊ฐœ์˜ ์ค„์—๋Š” ์ •์ˆ˜๋“ค์ด ์ฃผ์–ด์ง„๋‹ค. ์ž…๋ ฅ๋˜๋Š” ์ •์ˆ˜์˜ ์ ˆ๋Œ“๊ฐ’์€ 4,000์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

www.acmicpc.net

 

from collections import Counter
import sys

n = int(sys.stdin.readline())
num = []

for i in range(n):
    num.append(int(sys.stdin.readline()))

print(round(sum(num)/n))

num.sort()
print(num[n//2])

counter = Counter(num).most_common()
if len(counter) > 1 and counter[0][1] == counter[1][1]:
    print(counter[1][0])
else:
    print(counter[0][0])

print(max(num)-min(num))

 

Counter ํ•จ์ˆ˜

- from collections import Counter

- ๋ฆฌ์ŠคํŠธ ์›์†Œ ๊ฐœ์ˆ˜ ์…ˆ

- Counter(list).most_common() : ๋นˆ๋„๊ฐ’์ด ํฐ ์ˆœ์„œ๋Œ€๋กœ ์ถœ๋ ฅ!