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() : ๋น๋๊ฐ์ด ํฐ ์์๋๋ก ์ถ๋ ฅ!
'๐ค > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค 11650: ์ขํ ์ ๋ ฌํ๊ธฐ (Python) (0) | 2021.09.13 |
---|---|
๋ฐฑ์ค 1427: ์ํธ์ธ์ฌ์ด๋ (Python) (0) | 2021.09.13 |
๋ฐฑ์ค 10989: ์ ์ ๋ ฌํ๊ธฐ 3 (Python) (0) | 2021.09.10 |
๋ฐฑ์ค 2751: ์ ์ ๋ ฌํ๊ธฐ 2 (Python) (0) | 2021.09.10 |
๋ฐฑ์ค 2750: ์ ์ ๋ ฌํ๊ธฐ 1 (Python) (0) | 2021.09.10 |