문제 : https://www.acmicpc.net/problem/1157
코드
import sys
from collections import Counter
word = sys.stdin.readline().strip()
word = word.upper()
count = Counter(word)
m = [k for k,v in count.items() if max(count.values()) == v]
if len(m) == 1:
print("".join(m))
else:
print('?')
Counter를 사용해 딕셔너리로 푼 코드이다.
다른 풀이
word = input().upper()
word_list = list(set(word))
cnt = []
for i in word_list:
count = word.count
cnt.append(count(i))
if cnt.count(max(cnt)) > 1:
print("?")
else:
print(word_list[(cnt.index(max(cnt)))])
알파벳이 사용된 횟수를 리스트에 저장하는 방법으로도 풀 수 있다.
'코딩테스트 > 백준 (python)' 카테고리의 다른 글
백준 / 14425번 / 문자열 집합 / python 파이썬 (0) | 2024.06.05 |
---|---|
백준 / 2566번 / 최댓값 / python 파이썬 (0) | 2024.06.02 |
백준 / 15552번 / 빠른 A+B / python 파이썬 (0) | 2024.05.28 |
백준 / 1181번 / 단어 정렬 / python 파이썬 (0) | 2024.05.27 |
백준 / 11718번 / 그대로 출력하기 / python 파이썬 (0) | 2024.05.25 |