computer 지식/알고리즘 정복기
12933 오리 백준 파이썬
semper.fidelis
2021. 10. 13. 22:57
반응형
quack = input()
next_q ={
"q":"u",
"u":"a",
"a":"c",
"c":"k",
"k":"q"
}
temp=[]
printm1=False
for alphabet in quack:
last_change = " "
if len(temp)==0 and alphabet =="q":
temp.append(alphabet)
continue
else:
for temp_index in range(len(temp)):
if next_q[temp[temp_index][-1]] == alphabet:
temp[temp_index] += alphabet
last_change = temp[temp_index]
break
if alphabet =="q" and last_change[-1] !="q":
temp.append("q")
if alphabet !="q" and last_change==" ":
printm1 =True
for quackquack in temp:
if quackquack[-1] !="k":
printm1=True
if printm1:
print(-1)
else:
print(len(temp))
반응형