-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9935.py
More file actions
48 lines (48 loc) · 1.46 KB
/
9935.py
File metadata and controls
48 lines (48 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
string = input()
explode = input()
stack = []
flag = True # 출력이 없는 경우 체크
for i in range(len(string)):
char = string[i]
if char not in explode:
flag = False
if stack:
for j in range(len(stack)):
print(stack[j], end='')
print(char, end='')
stack = []
continue
# 폭발 문자의 첫 문자일 때 스택에 추가
if char == explode[0]:
stack.append(char)
# 폭발 문자열을 완성했다면 제거
if stack[-1] == explode[-1]:
for j in range(len(explode)):
stack.pop()
else:
if stack:
cur_idx = explode.index(char)
top_idx = explode.index(stack[-1])
# 순서가 알맞게 들어온 경우
if top_idx + 1 == cur_idx:
stack.append(char)
# 폭발 문자열을 완성헀다면 제거
if stack[-1] == explode[-1]:
for j in range(len(explode)):
stack.pop()
continue
# 순서가 잘못 들어온 경우
flag = False
if stack:
for j in range(len(stack)):
print(stack[j], end='')
print(char, end='')
stack = []
# 스택에 남아있는 문자들 처리
if stack:
flag = False
for j in range(len(stack)):
print(stack[j], end='')
# 출력이 한 번도 되지 않았을 때
if flag:
print('FRULA')