문제 풀이/Baekjoon Online Judge
[python3] 1157번 단어 공부
[잉간]
2019. 4. 2. 22:00
먼저 입력받은 문자열을 upper()를 사용해 대문자로 변환하고 collections.Counter()를 사용해 알파벳의 개수를 저장한다.
딕셔너리 형태로 저장된 알파벳 개수의 가장 큰 값과 알파벳의 value를 비교해 다르면 해당 알파벳을 제거한다.
최종적으로 딕셔너리에 남은 알파벳의 개수가 2개 이상일 경우 ?를 출력하고 아니면 해당 알파벳을 출력한다.
문제풀이
import collections string = collections.Counter(input().upper()) for k, v in dict(string).items(): if v != max(string.values()): del string[k] if len(string) >= 2: print("?") else: print("".join(list(string)))