MapleStory Finger Point

๐Ÿƒ‍โ™‚๏ธBaekjoon/Python

#1157 - python

HYEJU01 2024. 4. 20. 00:31
s = input().upper()  #๋ฌธ์ž์—ด ์ „์ฒด ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊ฟ”์ฃผ๊ธฐ ZzA
s_list = list(set(s)) #ZA

cnt = []
count = 0

for i in s_list :
    count = s.count(i) # Z  2
    cnt.append(count)# 2, 1
  
if cnt.count(max(cnt)) > 1 : #
    print("?")

else :
    print(s_list[(cnt.index(max(cnt)))])

 

1. ๋ฌธ์ž์—ด์„ ์ „๋ถ€ ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค. => ์—ฐ์‚ฐํ•˜๊ธฐ ํŽธํ•˜๋„๋ก ( count() ๋ฉ”์„œ๋“œ๋Š” ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ๋•Œ๋ฌธ์—)

2. ์ค‘๋ณต๋œ ๊ธ€์ž๋ฅผ ์—†์• ๊ธฐ ::  ๋ฌธ์ž์—ด์— ์žˆ๋Š” ๋ฌธ์ž ์ข…๋ฅ˜ 1๊ฐ€์ง€์”ฉ๋งŒ s_list ์— ๋„ฃ์–ด๋‘”๋‹ค. 

3. s.count(i) ๋ฅผ ํ†ตํ•ด s ๋ฆฌ์ŠคํŠธ์— s_list[0] ๊ฐ’์ด ๋ช‡๊ฐœ ์žˆ๋Š”์ง€ ์ถœ๋ ฅํ•ด์ค€๋‹ค.

4. ๊ทธ์ƒํƒœ๋กœ cnt ๋ผ๋Š” ๋ฆฌ์ŠคํŠธ์— ์‚ฝ์ž…

<-> ๋ฐ˜๋ณตํ•œ๋‹ค

5. ์ดํ›„ cnt ์ค‘ ์ตœ๊ณ ๊ฐ’์ด ์ œ์ผ ๋งŽ์€ ๋ฌธ์ž์ด๋‹ค.

6. cnt.count(max(cnt) ์ตœ๊ณ ๊ฐ’์ด cnt ์— ๋˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ( ์ตœ๊ณ ๊ฐ’์ด 1๊ฐœ ์ด์ƒ์ด๋ผ๋ฉด ? ๋ฅผ ์ถœ๋ ฅ)

7. ๋งˆ์ง€๋ง‰์œผ๋กœ cnt ๋Š” ์ตœ๊ณ ๊ฐ’ =(๋ฌธ์ž ๊ฐœ์ˆ˜์ด๋ฏ€๋กœ) ๋ฌธ์ž๋ฅผ ์ถœ๋ ฅํ•ด์ฃผ๊ธฐ ์œ„ํ•ด์„œ

=> ์ตœ๊ณ ๊ฐ’์˜ cnt ์ธ๋ฑ์Šค ๊ฐ’์„ ์ถœ๋ ฅํ•ด์„œ s_list[] ์ธ๋ฑ์Šค๋กœ ๋„ฃ์–ด์ฃผ๋ฉด ์ตœ๊ณ ๊ฐ’์˜ ๋ฌธ์ž๊ฐ€ ๋‚˜์˜จ๋‹ค.

 

 

 

 

๐Ÿ’ฌ  ๋ฆฌ์ŠคํŠธ.find("") : ํŠน์ • ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์˜ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜

๐Ÿ’ฌ set(s)๋Š” ๋ฌธ์ž์—ด s๋ฅผ ์ง‘ํ•ฉ์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ค‘๋ณต์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’ฌ  ๊ทธ ํ›„์— list() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์‹œ ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’ฌ ๋ฆฌ์ŠคํŠธ. count('์ฐพ์„๋ฌธ์ž์—ด')  ๋ฌธ์ž์—ด์—์„œ ํŠน์ • ๋ฌธ์ž ๋˜๋Š” ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์˜ ์ถœํ˜„ ํšŸ์ˆ˜

๐Ÿ’ฌ max()