본문 바로가기

Coding Test

백준 1157번 - count

words = input().upper()  # 입력값 대문자로 바꾸기 APPLE
word_list = list(set(words)) # set함수로 중복 제거 [A,P,L,E]
 
cnt = []  # max함수를 사용하기위해 리스트로 만들기 
for i in word_list: 
    count = words.count(i) # 입력값의 개수세기 
    cnt.append(count) # 센 개수값을 리스트에 넣기 [1, 2, 1, 1]
if cnt.count(max(cnt)) > 1: # max값이 2개이상일때 ?출력 
    print('?')
else:  
    print(word_list[cnt.index(max(cnt))]) # 개수가 가장 많은 알파벳을 출력 cnt.index(2), words_list[1] # P

 

'Coding Test' 카테고리의 다른 글

백준 10809번 - find  (0) 2022.03.14
백준 1065번 - list  (0) 2022.03.05
백준 4673번 - set  (0) 2022.03.04
백준 4344번 - 리스트, %.nf  (0) 2022.03.03
백준 2884번, 2525번 - if문  (0) 2022.02.23