We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8745f76 commit 46d7622Copy full SHA for 46d7622
minjeong/Simulation/2025-01-10-[백준]-#17413-단어뒤집기2.py
@@ -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
30
+ else:
31
+ # 단어를 temp에 저장
32
+ temp.append(S.popleft())
33
34
+# 남아 있는 단어 처리
35
+while temp:
36
37
38
+# 결과 출력
39
+print(''.join(answer))
0 commit comments