algorithm
[백준/python] 2941 - 크로아티아 알파벳
현재의 현제
2022. 6. 25. 15:10
a = list(input())
a.append(0)
pt = 0
cnt = 0
length = len(a)
while pt + 1 <= length:
if a[pt] == 'd' and a[pt + 1] == 'z' and a[pt + 2] == '=':
cnt += 1
pt += 3
elif a[pt] == 'c' and a[pt + 1] == '=':
cnt += 1
pt += 2
elif a[pt] == 'c' and a[pt + 1] == '-':
cnt += 1
pt += 2
elif a[pt] == 'd' and a[pt + 1] == '-':
cnt += 1
pt += 2
elif a[pt] == 'l' and a[pt + 1] == 'j':
cnt += 1
pt += 2
elif a[pt] == 'n' and a[pt + 1] == 'j':
cnt += 1
pt += 2
elif a[pt] == 's' and a[pt + 1] == '=':
cnt += 1
pt += 2
elif a[pt] == 'z' and a[pt + 1] == '=':
cnt += 1
pt += 2
else:
if a[pt] == 0:
break
cnt += 1
pt += 1
print(cnt)
처음에 a.append(0)를 한 이유: 마지막에 두 개로 구성된 크로아티아 알파벳의 첫 알파벳을 확인할 경우 a[pt + 1]가 리스트 범위를 초과하기 때문