알고리즘

2941-백준-크로아티아 알파벳

easysheep 2023. 2. 27. 22:44

1. 문제 출처

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

 

2941번: 크로아티아 알파벳

예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z=

www.acmicpc.net

2. 풀이

문자열을 이용한 단순 구현 문제이다..

# 크로아티아 문자 리스트 3글자인 것을 빼었다.
cro_list =\
["c=",
"c-",
"d-",
"lj",
"nj",
"s=",
"z="]
# 입력
string = input()

length = len(string)
total_count = length
idx = 0
# index가 list length을 넘지 않을 때
while idx < length:
    next_idx = idx+1
    if next_idx < length:
        # 다음 글자와 합친 값이 크로아티아 문자일때
        cro = string[idx]+string[next_idx]
        if cro in cro_list:
            total_count -=1
            idx +=2
            continue
        # 3개의 글자를 합쳤을 때 크로아티아 문자일 때
        elif (next_idx+1) < length:
            cro +=string[next_idx+1]
            if cro == "dz=":
                idx +=3
                total_count -=2
                continue
    idx+=1
    
        
print(total_count)