Skip to content

Commit 46d7622

Browse files
committed
[BOJ] #17413. 단어 뒤집기 2 / 실버3 / 45분 / 성공
1 parent 8745f76 commit 46d7622

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
from collections import deque
3+
4+
input = sys.stdin.readline
5+
6+
# 입력 문자열 처리
7+
S = deque(input().strip())
8+
temp = deque([]) # 단어를 저장하는 임시 리스트
9+
answer = deque([]) # 결과 저장 리스트
10+
11+
tag = False # 태그 상태 확인
12+
13+
while S:
14+
# 태그 시작
15+
if S[0] == "<":
16+
tag = True
17+
18+
# 태그 시작 또는 공백 처리
19+
if S[0] == " " or S[0] == "<":
20+
# temp에 저장된 단어 뒤집기
21+
while temp:
22+
answer.append(temp.pop())
23+
# 태그 내용 추가
24+
if tag:
25+
while S[0] != ">":
26+
answer.append(S.popleft())
27+
tag = False
28+
# 공백 또는 닫는 태그 추가
29+
answer.append(S.popleft())
30+
else:
31+
# 단어를 temp에 저장
32+
temp.append(S.popleft())
33+
34+
# 남아 있는 단어 처리
35+
while temp:
36+
answer.append(temp.pop())
37+
38+
# 결과 출력
39+
print(''.join(answer))

0 commit comments

Comments
 (0)