Python/백준 알고리즘
[백준][Python3] #1157. 단어 공부
2nan
2024. 3. 2. 16:40
728x90
코드 입력
word = input()
# 알파벳 정보를 담을 dictionary
alpha_dict = {}
while True:
# 단어의 가장 첫 음절
alpha = word[0]
# 음절 대문자와 소문자 개수 파악
cnt = word.count(alpha.upper()) + word.count(alpha.lower())
# 딕셔너리에 삽입
alpha_dict[alpha.upper()] = cnt
# 해당 음절 대문자 및 소문자 제거
word = word.replace(alpha.upper(), '').replace(alpha.lower(), '')
# 단어 길이가 1 미만일때까지 반복
if len(word) > 1:
continue
else:
break
# 딕셔너리의 값 중 가장 큰 값
max_value = max(alpha_dict.values())
# 최대값을 가진 원소 리스트에 담기
max_keys = [key for key, value in alpha_dict.items() if value == max_value]
# 리스트 개수로 파악
if len(max_keys) == 1:
print(max_keys[0])
else:
print('?')
출처 : 백준 Online Judge