๋ฌธ์
https://www.acmicpc.net/problem/9935
ํ์ด
# ๋ฐฑ์ค 9935๋ฒ ๋ฌธ์ - ๋ฌธ์์ด ํญ๋ฐ
import sys
input = sys.stdin.readline
# ์
๋ ฅ๊ฐ ์ฒ๋ฆฌ
s = input().rstrip()
bomb = input().rstrip()
# stack์ผ๋ก ๋ฌธ์์ด ํญ๋ฐ ๊ตฌํ
stack = []
bomb_length = len(bomb)
for char in s:
stack.append(char)
if ''.join(stack[-bomb_length:]) == bomb:
for _ in range(bomb_length):
stack.pop()
# ๊ฒฐ๊ณผ ์ถ๋ ฅ
if stack:
print(''.join(stack))
else:
print('FRULA')
๋ฌธ์์ด ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด O(n^2) ์ด๊ธฐ ๋๋ฌธ์ ์๊ฐ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ค.
์คํ ์๋ฃ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํด์ ํด๊ฒฐ์ ํ์๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Silver3] 1213๋ฒ_ํฐ๋ฆฐ๋๋กฌ ๋ง๋ค๊ธฐ (0) | 2023.04.04 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 1976๋ฒ_์ฌํ ๊ฐ์ (1) | 2023.04.03 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 1806๋ฒ_๋ถ๋ถํฉ (0) | 2023.04.01 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 11722๋ฒ_๊ฐ์ฅ ๊ธด ๊ฐ์ํ๋ ๋ถ๋ถ ์์ด (0) | 2023.03.31 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 2636๋ฒ_์น์ฆ (0) | 2023.03.31 |