๐ง Algorithm/Baekjoon๐ก
๐ก1157๋ฒ
4:Bee
2023. 12. 26. 22:29
728x90
๋จธ๋ฆฌ ์์์๋ ๊ทธ๋ ค์ ธ์์ง๋ง ํ์ํ ํจ์๋ค์ ์ ๋ชฐ๋ผ ํด๋งค๋ฏ ์์ฑ ํ๋ค ๊ตฌ๊ธ๋ง์ ํ๋ค. (๊ทธ๋ฅ ํจ์๋ฅผ ๋ชฐ๋ผ๋ ๋ชจ๋ฅด๋ ๋๋ก ์์์ ์ผ๋ก ์์ฑํด๋ ๊ด์ฐฎ์ ๊ฒ์ผ๊น?)
N = input()
n = list(set(N))
print(f"n(x) = {n}")
cnt_list = []
for x in n:
# n์ ์์๋ค์ x๊ฐ์ ๋ด๋๋ค. ๋ฐ๋ผ์ cnt_list๋ n์ ์์์ set ๋ฐฐ์น ์์๋๋ก ๋์ด๋์ด ์๋ค.
cnt = N.count(x) # x๋ ๊ณง n์ ์์์ด๋ค.
cnt_list.append(cnt)
print(f"cnt_list(N.count(x)) = {cnt_list}")
if cnt_list.count(max(cnt_list)) > 1:
# ์ต๋ max๊ฐ์ count ํ์ ๋ 2๊ฐ ์ด์ ์ด๋ฉด ?์ด๋ค.
print('?')
else:
max_index = cnt_list.index(max(cnt_list))
print(f"max_index = {max_index}")
print(n[max_index])
press
n(x) = ['p', 'r', 'e', 's']
cnt_list(N.count(x)) = [1, 1, 1, 2]
max_index = 3
s
n(x) = ['p', 'r', 'e', 's']
cnt_list(N.count(x)) = [1, 1, 1, 2]
max_index = 3
s
ํด๋น ์คํฌ๋ฆฝํธ์ ํด์ค๊ณผ ํ์ด ๋ฐฉ๋ฒ์ ๋ค์ ํฌ์คํ ์์ ๋์ฑ ๊ตฌ์ฒด์ ์ผ๋ก ํ์ธํด ๋ณด์. ์ฌ๊ธฐ์ ์ ์ฝ๋์ ๋ด๊ฐ ์ ์ ์ฃผ์์ผ๋ก ๋ง์กฑํ์.
728x90