문장이 입력되면 가장 많이 등장한 단어를 출력하세요. 동률이면 먼저 나온 단어를 출력하세요.
📥 테스트 입력값
apple banana apple cherry banana apple
🔎 실행 결과
apple
💡 힌트 코치
딕셔너리로 빈도를 세고 max 로 찾으세요.
✅ 정답 공개
words = input().split()
count = {}
order = []
for w in words:
if w not in count:
count[w] = 0
order.append(w)
count[w] += 1
best = order[0]
for w in order:
if count[w] > count[best]:
best = w
print(best)