알고리즘 문제풀이

Pen Pineapple Apple Pen (백준15881)

wiojfe 2023. 9. 14. 20:09

 pPAp의 문자열을 찾아야 하는데 문자열이 겹치는 부분이 있으면 안 된다. 

import sys 
input = sys.stdin.readline 
n = int(input())

string =input().rstrip()
cnt  = 0 
i = 0 
while True :
    if i > len(string)-3 :
        break 
    if string[i:i+4] == "pPAp" :
        cnt += 1 
        i += 4 
    else :
        i+= 1 
print(cnt )