๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
[v.๋ฐฐ์ด-ํต๊ณํ-2108]BAEKJOON_Python ๋ณธ๋ฌธ
220125 ์์ฑ
<๋ณธ ๋ธ๋ก๊ทธ๋ BAEKJOON ์ ์ฐธ๊ณ ํด์ ์ ๋ง์ ํ์ด๋ฅผ ์์ฑํ์์ต๋๋ค>
2108
์ฒซ์งธ ์ค์๋ ์ฐ์ ํ๊ท ์ ์ถ๋ ฅ (์์์ ์ดํ ์ฒซ์งธ ์๋ฆฌ์์ ๋ฐ์ฌ๋ฆผํ ๊ฐ์ ์ถ๋ ฅ)
๋์งธ ์ค์๋ ์ค์๊ฐ์ ์ถ๋ ฅ
์ ์งธ ์ค์๋ ์ต๋น๊ฐ์ ์ถ๋ ฅ (์ฌ๋ฌ ๊ฐ ์์ ๋์๋ ์ต๋น๊ฐ ์ค ๋ ๋ฒ์งธ๋ก ์์ ๊ฐ์ ์ถ๋ ฅ)
๋ท์งธ ์ค์๋ ๋ฒ์๋ฅผ ์ถ๋ ฅ
๋ด ํ์ด
import sys
from collections import Counter
a = int(sys.stdin.readline())
num = []
for i in range(a) :
num.append(int(sys.stdin.readline()))
def mean (nums) :
return round(sum(nums)/a)
def median (nums) :
nums.sort()
mid = nums[len(nums)//2]
return mid
def mode(nums) :
mode_dict = Counter(nums)
modes = mode_dict.most_common()
if len(nums) > 1 :
if modes[0][1] == modes[1][1] :
mod = modes[1][0]
else :
mod = modes[0][0]
else :
mod = modes[0][0]
return mod
def scope(nums) :
return max(nums) - min(nums)
print(mean(num))
print(median(num))
print(mode(num))
print(scope(num))
collections.Counter()
: ๊ฐ ํญ๋ชฉ๋น ์ค๋ณต๋๋ ๊ฐ์๋ฅผ ๋ฆฌํดํ๋๋ฐ ๊ธฐ๋ณธ์ผ๋ก ๋์๋๋ฆฌ ํํ๋ก!
: ๊ฐ์ ๋น๋๋ฅผ ๊ฐ์ง๋ ์๋ ์๋ ์ํ์ค์ ์๋ ์์๋๋ก ๋์ด
: modes[0][1]์ ๊ฐ์ฅ ์์ ์๋ ์ต๋น๊ฐ์ ๋น๋์
: modes[1][1]์ ๊ทธ ๋ค์ ์ต๋น๊ฐ์ ๋น๋์
: ๋๋ฒ์งธ๋ก ์์ ๊ฐ์ ์ฑํํด์ผ ํ๋ฏ๋ก modes[1][0]
5
1
3
8
-2
2
// ๊ฒฐ๊ณผ
2
2
1
10
collection... ์ฒจ ์จ๋ณด๋น
์ฐธ๊ณ ํ์์ต๋๋ค : -)
https://roseline124.github.io/algorithm/2019/03/22/Algorithm-baekjoon-2108.html
์ ํนํ๋ ๊ฐ๋ฐํ๊ธฐ
Python, Django, ๋ฐ์ดํฐ ๋ถ์, ์๊ณ ๋ฆฌ์ฆ ๋ฑ ๋งค์ผ ๊ณต๋ถํ ๋ด์ฉ์ ๊ธฐ๋กํฉ๋๋ค.
roseline124.github.io
+) ์๋ ๋๋๋ฐ ๋ฐํ์ ์๋ฌ,,,
import numpy as np
from scipy import stats
a = int(input())
num = []
for i in range(a) :
num.append(int(input()))
num = sorted(num)
print("%.1d" %np.mean(num))
print(np.median(num))
print(int(stats.mode(num)[1]))
print(np.max(num) - np.min(num))
'๐ฆฅ ์ฝํ > BAEKJOON' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[v.๋ฐฐ์ด-์ขํ ์ ๋ ฌํ๊ธฐ-11650]BAEKJOON_Python (0) | 2022.01.25 |
---|---|
[v.๋ฐฐ์ด-์ํธ์ธ์ฌ์ด๋-1427]BAEKJOON_Python (0) | 2022.01.25 |
[v.๋ฐฐ์ด-์ ์ ๋ ฌํ๊ธฐ3-10989]BAEKJOON_Python (0) | 2022.01.19 |
[v.๋ฐฐ์ด-์ ์ ๋ ฌํ๊ธฐ2-2751]BAEKJOON_Python (0) | 2022.01.19 |
[v.๋ฐฐ์ด-์ ์ ๋ ฌํ๊ธฐ-2750]BAEKJOON_Python (0) | 2022.01.19 |