본문 바로가기

Development/Algorithm

[Algorithm] 백준 1157번 문제풀이

728x90

 

Baekjoon Logo

 

이 글은 백준 알고리즘 단계별로 문제풀기 1157번 문제에 대한 풀이입니다. 자세한 내용은 코드 내의 주석을 참고해주시면 감사하겠습니다.
import string

# Making dictionary of alphabet order
d = dict.fromkeys(string.ascii_uppercase, 0)

word = input()

# Converting uppercase if word is lowercase
word = word.upper()
for i in range(len(word)):
    d[word[i]] += 1

# Extracting max value in alphabet dictionary
d_max_value = max(d.values())

# Extracting keys related to max value
d_max_keys = list()
for key, value in d.items():
    if value == d_max_value:
        d_max_keys.append(key)

if len(d_max_keys) != 1:
    print("?")
else: 
    print(d_max_keys[0])
728x90