Problem:
Switching Railroad Cars   This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks. We can simulate the movement (comings and goings) of the cars as follow:  An entry of a car is represented by its number.  An exit of a car is represented by 0  For example, a sequence 1
6
0
8
10 demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter. Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks. Input car number
car number or 0
car number or 0
  .
  .
  .
car number or 0 The number of input lines is less than or equal to 100. Output For each 0, print the car number. Sample Input 1
6
0
8
10
0
0
0 Output for the Sample Input 6
10
8
1

Solution (Python):
from collections import deque
d = deque()
while True:
    try:
        n = int(input())
        if n == 0:
            print(d.pop())
        else:
            d.append(n)
        
    except EOFError:
        break

Solution (Python):
s = []

while 1:
    try:
        d = int(input())
    except:
        break
    if d == 0:
        print(s.pop())
    else:
        s.append(d)

Solution (Python):
try:
    num = []
    while True:
        
        i = int(input())
        
        if i == 0:
            print(num[-1])
            num.pop(-1)
        else:num.append(i)

except EOFError:
    pass

Solution (Python):
a = []
while True:
    try:
        t = input()
    except:
        break
    if t == "0":
        print(a.pop())
    else:
        a.append(t)

Solution (Python):
a = []
i = 0
while True:
    try:
        n = int(input())
        if (n):
            a.append(n)
            i += 1
        else:
            i -= 1
            print(a[i])
            a.pop()

    except EOFError:
        break

Solution (Python):
s = []
while 1:
    try:
        n = int(input())
        if n == 0:
            print(s.pop())
        else:
            s.append(n)
    except:
        break

Solution (Python):
import sys
numbers = []
try:
    while True:
        a = int(input())
        if a != 0:
            numbers.append(a)
        elif a == 0:
            print(numbers.pop())
except Exception:
    sys.exit()

Solution (Python):
a = [] 
while True: 
  try: 
    i = int(input()) 
  except: 
    break
  if i == 0: 
    c = a.pop() 
    print(c) 
  else: 
    a.append(i)

Solution (Python):
l1 = []
l2 = []
try:
    while(True):
        n = int(input())
        if n == 0:
            l2.append(l1[-1])
            del l1[-1]
        else:
            l1.append(n)
except:
    pass

for i in l2:
    print(i)

Solution (Python):
list=[]

while True:
  try:
    n = int(input())
    if n==0:
      print(list.pop())
    else:
      list.append(n)
  except EOFError:
    break

Solution (Python):
from collections import deque
q=deque([])
while True:
    try:
        n=int(input())
    except:
        break
    if n==0:
        print(q.pop())
    else:
        q.append(n)

Solution (Python):
D=[]
while True:
  try:
    n=int(input())
    if n==0:
      print(D.pop(-1))
    else:
      D.append(n)
  except EOFError:
    break

Solution (Python):
from collections import deque
cars=deque()
while(True):
    try:
        n=int(input())
        print(cars.popleft()) if n==0 else cars.appendleft(n)
    except:
        break

Solution (Python):
if __name__ == '__main__':

	A = []

	while True:
		try:
			n = int(input())
			if n == 0:
				print(A[-1])
				A.pop(-1)
			else:
				A.append(n)
		except EOFError:
			break

Solution (Python):
c = []
while True:
  try:
    n = int(input())
    if n == 0:
      print(c.pop())
    else:
      c.append(n)
  except EOFError:
    break

Solution (Python):
car = []
while True:
   try:
       x =int(input())
       if x == 0:
            print(car.pop())
       else:
           car.append(x)
   except:break

Solution (Python):
car = []
while 1:
    try:
        i = int(input())
        if  i == 0:
            print(car.pop()) 
        else:
            car.append(i)
    except ValueError:
        print(car)
        for j in range(len(car)):
            print(car.pop())
        break
    except EOFError:
        break

Solution (Python):
cars = []
while True:
    try:
        inVal = int(input())
        if inVal == 0:
            print(cars.pop(-1))
        else:
            cars.append(inVal)
    except EOFError:
        break

Solution (Python):
import sys

stack = []
for line in sys.stdin:
	n = int(line)
	if n == 0:
		print stack.pop(-1)
	else: stack.append(n)

Solution (Python):
car=[]
while True:
    try:
        n=int(input())
        if n!=0:
            car.append(n)
        else:
            print(car.pop())
    except:break

Solution (Python):
stack = []
while True:
  try:
    num = int(input())
  except EOFError:
    break
  if num != 0:
    stack.append(num)
  elif num == 0:
    print(stack.pop(-1))

Solution (Python):
import sys
  
stack = []

for nstr in sys.stdin:
    n = int(nstr)
    if n == 0:
        print(stack.pop())
    else:
        stack.append(n)

Solution (Python):
list1 = []
for i in range(1, 200):

    try:
        str1 = input()
        if str1 != '0' and str1 != '':
            list1.append(str1)
        elif str1 == '0':
            print(list1.pop())
        else:
            break
    except:
        break

Solution (Python):
stack = []

while True:
    try:
        data = int(input())
        if data == 0:
            print stack.pop()
        else:
            stack.append(data)
    except:
        break

Solution (Python):
if __name__ == '__main__':
    lst = []
    while True:
        try:
            n = int(input())
            if n == 0:
                print (lst.pop())
            else:
                lst.append(n)
        except EOFError:
            break

Solution (Python):
x = []
while(1):
    try:
        a = int(input())
        if a == 0:
            print(x[-1])
            x.pop(len(x)-1)


        else:
            x.append(a)
    except EOFError:
        break

Solution (Python):
stack = []
while True:
    try:
        i = input()
        if i == "0":
            print(stack.pop(0))
        else:
            stack.insert(0, i)
    except EOFError:
        break

Solution (Python):
l = []

while(1):
    try:
        n = int(input())
    except:
        break

    if n == 0:
        ans = l.pop(-1)
        print(ans)
    else:
        l.append(n)

Solution (Python):
li = []
while True:
    try:
        n = int(input())
    except:
        break
    
    if n == 0:
        print(li.pop())
    else:
        li.append(n)

Solution (Python):
ans = []
while True:
    try:
        x = int(input())
        if x == 0:
            print(ans.pop())
        else:
            ans.append(x)
    except: break

Solution (Python):
ar = []
while(True):
    try:
        n = int(input())
        if n == 0:
            print(ar.pop())
        else:
            ar.append(n)
    except:
        break

Solution (Python):
q = []

while True:
  try:
    i = int(input())
    if i == 0:
      print(q.pop())
    else:
      q.append( i )
  except:
    break

Solution (Python):
waits=[]
while 1:
    try:
        i=input()
        if i=="0":
            print(waits[-1])
            waits.pop()
        else:
            waits.append(i)
    except:break

Solution (Python):
from collections import deque
import sys

train = deque([])
for line in sys.stdin:
    n = int(line)
    if n == 0:
        t = train.popleft()
        print(t)
    else:
        train.appendleft(n)

Solution (Python):
nlist = []
while 1:
    try:
        n = int(input())
        if n == 0:
            print(nlist.pop(-1))
        else:
            nlist.append(n)
    except:
        break

Solution (Python):
import sys


def main():
    stack = []
    for x in sys.stdin:
        x = int(x)
        if x:
            stack.append(x)
        else:
            print(stack.pop())


if __name__ == '__main__':
    main()

Solution (Python):

from collections import deque
num = int(input())
stk = deque()
while 1:
    if num == 0:
        print(stk.pop())
    else:
        stk.append(num)
    try: num = int(input())
    except EOFError: break
while stk: print(stk.pop())