https://www.acmicpc.net/problem/16120
스택을 활용한 문제
스택을 사용하여 PPAP 패턴을 체크
for i in s:
stk.append(i)
if len(stk) >= 4 and stk[-4:] == ['P','P','A','P']
연속된 PPAP를 하나의 P로 간주하여 줄여나갑니다.
if len(stk) >= 4 and stk[-4:] == ['P','P','A','P']:
stk[-4:] = ['P']
마지막에 P만 남게 되면 PPAP 문자열이고 아니라면 NP를 출력
print('PPAP' if stk == ['P'] else 'NP')
import sys
input = sys.stdin.readline
s = input().rstrip()
stk = []
for i in s:
stk.append(i)
if len(stk) >= 4 and stk[-4:] == ['P','P','A','P']:
stk[-4:] = ['P']
print('PPAP' if stk == ['P'] else 'NP')