-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
50 lines (38 loc) · 983 Bytes
/
code.py
File metadata and controls
50 lines (38 loc) · 983 Bytes
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
49
50
def Push(x,stack1,stack2):
'''
x: value to push
stack1: list
stack2: list
'''
stack1.append(x)
def Pop(stack1,stack2):
'''
stack1: list
stack2: list
'''
while len(stack1) > 0 :
stack2.append(stack1.pop())
element = -1
if len(stack2) > 0 :
element = stack2.pop()
while len(stack2) > 0 :
stack1.append(stack2.pop())
return element
if __name__ == '__main__':
test_cases = int(input())
for cases in range(test_cases):
qry=int(input())
qtyp_qry=list(map(int, input().strip().split()))
i=0
stack1=[]
stack2=[]
while i <len(qtyp_qry):
#print(i)
if qtyp_qry[i]==1:
Push(qtyp_qry[i+1],stack1,stack2)
#print(i)
i+=2
else:
print(Pop(stack1,stack2),end=' ')
i+=1
print()