[Python] [백준 #1157] 단어 공부

박수경·2021년 11월 7일

문제

1157

푸는 과정

우선 입력을 받는다. 그 후 중복을 제거하는 set의 특성을 이용해 word_list를 만들어준다.

word = input().upper()
word_list = list(set(word))

count()를 이용해 문자를 하나씩 세준다.

word = input().upper()
word_list = list(set(word))
cnt = []

for i in word_list:
    cnt.append(word.count(i))

그 다음에 ?가 뜰 조건을 세워주고 else로 나머지 경우를 출력한다.

word = input().upper()
word_list = list(set(word))
cnt = []

for i in word_list:
    cnt.append(word.count(i))

if cnt.count(max(cnt)) >= 2:
    print("?")
else:
    print(word_list[(cnt.index(max(cnt)))])

결과

이번 문제는 아이디어가 도저히 떠오르지 않아 다른 분들의 아이디어를 조금 엿보았다. 언제쯤 막히지 않고 술술 풀 수 있으려나.

profile
유니콘을 위하여

0개의 댓글