백준 / 방번호 / 1475

박성완·2022년 4월 18일
0

백준

목록 보기
67/78
post-thumbnail

Question

문제링크
Silver 5

Logic

기본 구조 : dictionary
1. 각 숫자별로 값이 0인 딕셔너리를 생성한다.
2. 입력값을 한 자리씩 읽어 갯수를 센다. 이 때 6과 9는 합쳐서 따로 카운트한다.
3. 비교를 완료하면 6+9의 갯수를 2로 나누고 올림한 값과, 다른 수 갯수의 최댓값 중 큰 수를 출력한다.

Code

from sys import stdin
from math import ceil
N = stdin.readline().rstrip()
dic = {str(i):0 for i in range(0,10)}
cnt = 0
for s in N:
    if s=='6' or s=='9' : cnt+=1
    else : dic[s]+=1
print(max(max(dic.values()),ceil(cnt/2)))

0개의 댓글