728x90
import sys
from collections import Counter
n = int(sys.stdin.readline())
player = []
fn = []
cnt = 0
for i in range(n):
a = sys.stdin.readline().rstrip()
player.append(a[0]) #1
player_count = Counter(player) #2
for i, j in player_count.items(): #3
if j >= 5: #4
fn.append(i)
cnt += 1 #5
fn.sort() #6
if cnt == 0: #7
print("PREDAJA")
else:
for i in fn: #8
print(i, end='')
#1 : 첫글자만 입력
#2 : Counter함수를 사용해서 내부 문자열을 해시처럼 만들어준다
#3 : key, value로 구분해서(튜플로) i, j로 빼준다
#4 : 개수가 5개가 넘으면 리스트에 추가하고
#5 : cnt += 1
#6 : 사전순으로 출력해야 하니까 정렬
#7: 5개 넘는 알파벳이 하나도 없으면 지정된 문자 출력
#8 : 아니면 알파벳 붙여서 출력
https://hgk5722.tistory.com/57
https://hgk5722.tistory.com/143
Counter모듈을 사용하는 문제였습니다.
https://hgk5722.tistory.com/144
728x90
'[PS(Problem Solving)] > [백준]' 카테고리의 다른 글
[백준] 11655 파이썬(python) : ROT13 - 기초지식 (0) | 2022.07.19 |
---|---|
[백준] 10610 파이썬(python) : 30 (0) | 2022.07.19 |
[백준] 10798 파이썬(python) : 세로읽기 - 사이즈계산 (0) | 2022.07.18 |
[백준] 5525 파이썬(python) : IOIOI (0) | 2022.07.18 |
[백준] 9935 파이썬(python) : 문자열 폭발 (0) | 2022.07.18 |