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

3-1

간단한 문자열 문제이다.

입력으로 주어진 단어의 크로아티아 알파벳 갯수를 출력한다.

일단 크로아티아 알파벳의 정보를 담고있는 dictionary를 만들어 줘보자.

이후 특별히 긴 알파벳의 시작을 보면 c,d,l,n,s,z일때만 1자리 뒤에까지 check해주고 dz일때는 3번째까지 check해준다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
x = input()
d = ["c=","c-","dz=",'d-','lj','nj','s=','z=']
special = ['c','d','l','n','s','z']
cnt = 0
i = 0
while i<len(x):
if x[i] in special:
if i<len(x)-2 and x[i]+x[i+1]+x[i+2] == 'dz=':
i+=3
cnt+=1
elif i<len(x)-1 and x[i]+x[i+1] in d:
i+=2
cnt+=1
else:
cnt+=1
i+=1
else:
cnt+=1
i+=1
print(cnt)

index의 조작이 필요해 for문이 아닌 while문을 사용했고, 딱히 어려운 문제는 아니였다.

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

https://jo-member.github.io/2021/01/02/2020-01-02-boj2941/

Author

jo-member

Posted on

2021-01-02

Updated on

2021-04-22

Licensed under

Comments