https://www.acmicpc.net/problem/2941
문제 분석
- 단어가 주어졌을 때 몇 개의 글자가 크로아티아 알파벳으로 이루어져있는지 출력
코드 설계
- replace
정답 코드
1차 - 실패
import sys
input = sys.stdin.readline
word = input().strip()
cro = ['c=', 'c-', 'dz=', 'd-', 'lj', 'nj', 's=', 'z=']
check = ''
cnt = 0
for w in word:
check += w
if check in cro:
print(check)
cnt += len(check)
check = ''
print(cnt)
2차 - replace
import sys
input = sys.stdin.readline
word = input().strip()
cro = ['c=', 'c-', 'dz=', 'd-', 'lj', 'nj', 's=', 'z=']
for c in cro :
word = word.replace(c, '*')
print(len(word))
'코딩 테스트 > 백준' 카테고리의 다른 글
[Python] 백준 1655 가운데를 말해요 (0) | 2025.04.22 |
---|---|
[Python] 백준 11726 2xn 타일링 (0) | 2025.04.22 |
[Python] 백준 2294 동전 2 (0) | 2025.04.17 |
[Python] 백준 1261 알고스팟 (0) | 2025.04.15 |
[Python] 백준 1149 RGB 거리 (0) | 2025.04.14 |