[백준] #1157 문자열 upper, lower python

2022. 12. 22. 13:19

https://www.acmicpc.net/problem/1157

 

1157번: 단어 공부

알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다.

www.acmicpc.net

 

upper, lower의 사용 알기.

 

 

S = input()

S_dict = {}
for i in S:
    if i.upper() not in S_dict:
        S_dict[i.upper()] = [0]
    elif i.upper() in S_dict:
        S_dict[i.upper()].append(0)
result = ""
max_ = -10000
for i in S_dict:
    if len(S_dict[i]) > max_:
        max_ = len(S_dict[i])
        result = i
cnt = 0
for i in S_dict:
    if len(S_dict[i]) == max_:
        cnt += 1
if cnt > 1:
    print("?")
else:
    print(result)

 

BELATED ARTICLES

more