We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6c7d876 commit 66e86d7Copy full SHA for 66e86d7
minjeong/Stack, Queue/2024-12-06-[백준]-#14713-앵무새.py
@@ -0,0 +1,31 @@
1
+import sys
2
+from collections import deque
3
+
4
+input = sys.stdin.readline
5
6
+N = int(input()) # 앵무새 수
7
+S = [] # 앵무새 문장
8
+for _ in range(N):
9
+ S.append(deque(input().split()))
10
+L = deque(input().split()) # 받아 적은 문장
11
12
+while L:
13
+ current = L.popleft() # 현재 단어
14
+ found = False
15
16
+ # 각 앵무새 문장에서 단어 찾기
17
+ for s in S:
18
+ if s and s[0] == current: # 매칭되는 단어가 있다면
19
+ s.popleft() # 단어 제거
20
+ found = True
21
+ break
22
23
+ if not found: # 매칭되는 단어가 없으면 Impossible
24
+ print("Impossible")
25
+ exit()
26
27
+# 모든 문장이 비었는지 확인
28
+if any(s for s in S): # S에 남은 문장이 있다면 Impossible
29
30
+else:
31
+ print("Possible")
0 commit comments