๐๋ฌธ์ :
๐ํ์ด:
์ ๋ ฅ๋ฐ๋ ์ซ์๋ค์ ๋ฆฌ์คํธ๊ฐ ์๋ ๋์ ๋๋ฆฌ ํํ๋ก ์ ์ฅํ์ฌ ๋น๋ ์๋ฅผ ํจ๊ป ์ ์ฅํ๋ค.
๋์ ๋๋ฆฌ๋ฅผ ์ ๋ ฌํ๋ ๋ฐฉ๋ฒ์ด ๊ธฐ์ต์ด ์๋์ ๊ตฌ๊ธ๋ง์ ํ๋ค...
โ๏ธ์ฝ๋:
'''
https://www.acmicpc.net/problem/2108
๋ฌธ์ : ํต๊ณํ
๋์ด๋: ์ค๋ฒ3
'''
import sys
def myround(num):
a = int(num)
b = num - a
if b >= 0.5:
return a + 1
elif b <= -0.5:
return a - 1
else:
return a
index = int(input())
box = {}
for i in range(index):
num = int(sys.stdin.readline())
if num not in box:
box[num] = 1
else:
box[num] += 1
sorted_by_key = dict(sorted(box.items(), key=lambda item: item[0])) # ์ซ์ ํฌ๊ธฐ ์์ผ๋ก ์ ๋ ฌ
sorted_list = list(sorted_by_key.keys())
sorted_by_value = dict(sorted(box.items(), key=lambda item: (-item[1], item[0]))) # ๋น๋ ์์ผ๋ก ์ ๋ ฌ
freq_list = list(sorted_by_value.items())
# ์ฐ์ ํ๊ท ์ถ๋ ฅ
sum = 0
for m, n in sorted_by_key.items():
sum += m*n
print(myround(sum/index))
# ์ค๊ฐ๊ฐ ์ถ๋ ฅ
n = 0
cur_index = 0
middle = 0
while cur_index <= int(index/2):
middle = sorted_list[n]
cur_index += sorted_by_key[middle]
n+=1
print(middle)
# ์ต๋น๊ฐ ์ถ๋ ฅ
if index == 1: # ์์๊ฐ ํ๋ ์ผ๋
print(freq_list[0][0])
else:
# ์ฒซ ๋ฒ์งธ ์์์ ํค์ ๊ฐ
first_key, first_value = freq_list[0]
# ๋ ๋ฒ์งธ ์์์ ํค์ ๊ฐ
second_key, second_value = freq_list[1]
if first_value == second_value:
print(second_key)
else:
print(first_key)
# ๋ฒ์
print(sorted_list[-1] - sorted_list[0])
๐๋งํฌ:
'๐งฉps > ๐ฅNormal' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 2096๋ฒ] ๋ด๋ ค๊ฐ๊ธฐ (1) | 2024.10.13 |
---|---|
[๋ฐฑ์ค 18115๋ฒ] ์์ด๊ณผ ์ฟผ๋ฆฌ 38 (0) | 2024.10.01 |
[๋ฐฑ์ค 1654๋ฒ] ๋์ ์๋ฅด๊ธฐ (0) | 2024.09.29 |
[๋ฐฑ์ค 1874๋ฒ] ์คํ ์์ด (0) | 2024.09.27 |
[๋ฐฑ์ค 1966๋ฒ] ํ๋ฆฐํฐ ํ (0) | 2024.09.26 |