[백준 2941] 크로아티아 알파벳

코뉴·2022년 1월 24일
0

백준🍳

목록 보기
74/149

https://www.acmicpc.net/problem/2941

🥚문제


🥚입력/출력


🍳코드

from collections import deque
import sys
input = sys.stdin.readline

string = input().strip()

# 3글자짜리 "dz="가 "z="보다 먼저 replace될 수 있게 앞에 배치alphabet = ["dz=", "c=", "c-", "d-", "lj", "nj", "s=", "z="]

for x in alphabet:
    string = string.replace(x, "*")

print(len(string))

🧂아이디어

구현, 문자열

  • 문자열을 변경하는 replace 함수를 사용하여 크로아티아 알파벳을 "*"로 변환했다.
  • 이때, 3글자로 구성된 "dz="를 우선적으로 replace한다. 그렇지 않으면 "dz="에서 "z="가 먼저 바뀌게 되므로 글자수를 올바르게 셀 수 없다.
profile
코뉴의 도딩기록

0개의 댓글