๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • What would life be If we had no courage to attemp anything?
Problem Solving/BAEKJOON

[baekjoon]python #2108 ํ†ต๊ณ„ํ•™

by DevIseo 2022. 6. 24.

[baekjoon]python #2108 ํ†ต๊ณ„ํ•™

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

 

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

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

www.acmicpc.net

 

import sys
from collections import Counter
input = sys.stdin.readline
N=int(input())
arr=[]
for _ in range(N):
    arr.append(int(input()))

#์‚ฐ์ˆ ํ‰๊ท 
print(round(sum(arr)/N))
arr.sort()
#์ค‘์•™๊ฐ’
print(arr[len(arr)//2])
#์ตœ๋นˆ๊ฐ’
cnt=Counter(arr).most_common()
#cnt = [(๊ฐ’,๊ฐฏ์ˆ˜),(๊ฐ’,๊ฐฏ์ˆ˜)...]๋‚ด๋ฆผ์ฐจ์ˆœ!
if len(cnt)>1:
    if cnt[0][1] == cnt[1][1]:
        print(cnt[1][0])

    else:
        print(cnt[0][0])
else:
    print(cnt[0][0])

#๋ฒ”์œ„
print(max(arr)-min(arr))

๋Œ“๊ธ€