https://www.acmicpc.net/problem/9935
# 초기 답안
import sys
# 입력값 처리
S = sys.stdin.readline().rstrip()
explosion_string = sys.stdin.readline().rstrip()
# 문자열 폭발 탐색
while explosion_string in S:
S = S.replace(explosion_string, '')
# 결과 출력
if S:
print(S)
else:
print('FRULA')
# 개선 답안
import sys
# 입력값 처리
S = sys.stdin.readline().rstrip()
explosion_string = sys.stdin.readline().rstrip()
# stack으로 문자열 폭발 구현
stack = []
ex_len = len(explosion_string)
for i in range(len(S)):
stack.append(S[i])
if ''.join(stack[-ex_len:]) == explosion_string:
for _ in range(ex_len):
stack.pop()
# 결과 출력
if stack:
print(''.join(stack))
else:
print('FRULA')
stack 자료구조를 제가 사용한 것보다 간결하게 활용하셔서 도움이 많이 되었습니다! 👍