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



Sample input:
1
6
0
8
10
0
0
0


Sample output:
6
10
8
1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
garage = []
cars = []
while True:
    num = int(input())
    if num == 0:
        cars.append(garage.pop())
    else:
        garage.append(num)
        print(garage)
    if not garage:
        break
[print(car) for car in cars]

Submission status: Wrong Answer

Solution code:
garage = []
cars = []
while True:
    num = int(input())
    if num == 0:
        cars.append(garage.pop())
    else:
        garage.append(num)
    if not garage:
        break
[print(car) for car in cars]

Submission status: Wrong Answer

Solution code:
garage = []
while True:
    num = int(input())
    if num == 0:
        print(garage.pop())
    else:
        garage.append(num)
    if not garage:
        break

Submission status: Wrong Answer

Solution code:
rail = []
while True:
  n = int(raw_input())
  if n != 0:
    rail.append(n)
  else:
    print rail.pop()

  if len(rail) == 0:
    break

Submission status: Wrong Answer

Solution code:
stack = []
while True:
    a = int(input())
    if a == 0:
        print(stack.pop())
    else:
        stack.append(a)
    if len(stack) == 0:
        exit()

Submission status: Wrong Answer

Solution code:
li = []
li.append(int(input()))
depth = 1
while depth > 0:
    x = int(input())
    if x == 0:
        print(li.pop())
        depth -= 1
    else:
        li.append(x)
        depth += 1

Submission status: Wrong Answer

Solution code:
a = []
while True:
    s = int(input())
    if s != 0:
        a.append(s)
    else:
        print(a.pop())
    if len(a) == 0:
        break

Submission status: Wrong Answer

Solution code:
lis=[]
lis.append(input())

while lis!=[]:
    inp=input()
    if inp==0:
        print lis[-1]
        del lis[-1]
    else:
        lis.append(inp)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
L=[]
while True:
    try:
        n=int(input())
        if n==0:
            L.pop()
        else:
            L.append(n)
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
s=[int(input())]
while(len(s)!=0):
    n=int(input())
    if n==0:
        print(s.pop())
    else:
        s.append(n)

Submission status: Wrong Answer

Solution code:
list = {}
while True:
    try:
        num = int(input())
        if num == 0:
            print(list.pop())
        else:
            list.append(num)
    except:
        break

Submission status: Wrong Answer

Solution code:
stack = []
stack.append(int(input()))
while stack:
    inp = int(input())
    if inp == 0:
        a = stack[-1]
        del stack[-1]
        print(a)
    else:
        stack.append(inp)

Submission status: Wrong Answer

Solution code:
stack = []
stack.append(int(input()))
ans= []
while stack:
    inp = int(input())
    if inp == 0:
        a = stack[-1]
        del stack[-1]
        ans.append(a)
    else:
        stack.append(inp)
print(*ans, sep="\n")

Submission status: Wrong Answer

Solution code:
# coding:utf-8

syako = []
try:
    while True:
        number = int(raw_input())
        if number != 0:
            syako.append(number)
        elif number == 0:
            print syako.pop()
        number = int(raw_input())
except:
    pass

Submission status: Wrong Answer

Solution code:
i= 0
a,b = [],[]

while True:
    try:
        a.append(int(raw_input()))
        #print a
        if a[i] == 0:
            b.append(a[i-1])
            a.pop()
            a.pop()
            i -=1
        else:
            i +=1

        if len(a)== 0:
            break
        else:
            continue
    except:
        #print "bbbbbbbb"
        break


for k in range(0,len(b)):
    print b[k]

Submission status: Wrong Answer

Solution code:
i= 0
a,b = [],[]

while True:
    try:
        a.append(int(raw_input()))
        #print a
        if a[i] == 0:
            b.append(a[i-1])
            a.pop()
            #print i
            print a[i-1]
            a.pop()
            i -=1
        else:
            i +=1

        if len(a)== 0:
            break
        else:
            continue
    except:
        #print "bbbbbbbb"
        break

Submission status: Wrong Answer

Solution code:
i= 0
a,b = [],[]

while True:
    try:
        a.append(int(raw_input()))

        if a[i] == 0:
            b.append(a[i-1])
            a.pop()
            print a[i-1]
            a.pop()
            i -=1
        else:
            i +=1

        if len(a)== 0:
            break
        else:
            continue
    except:
        break

Submission status: Wrong Answer

Solution code:
a=[]
while 1:
 try:n=int(input());a.append(e)if e else print(a.pop())
 except:break

Submission status: Wrong Answer

Solution code:
import sys
a=[map(int,i)for i in sys.stdin]

b=[]
print(a)
for j in a:
	if j == 0:
		print(b.pop())
	else:
		b.append(j)

Submission status: Wrong Answer

Solution code:
import sys
a=[int(i)for i in sys.stdin]

b=[]
print(a)
for j in a:
	if j == 0:
		print(b.pop())
	else:
		b.append(j)

Submission status: Wrong Answer

Solution code:
import sys
a=[map(int,i)for i in sys.stdin]

b=[]
for j in a:
	if j == 0:
		print(b.pop())
	else:
		b.append(j)

Submission status: Wrong Answer

Solution code:
import sys
a=[int(i)for i in sys.stdin]

b=[]
print(a)
for j in a:
	if j == 0:
		print(b.pop())
	else:
		b.append(j)

Submission status: Wrong Answer

Solution code:
l=[]
l.append(int(input()))
while l:
    o=int(input())
    if not o:
        print(l.pop())
    else:
        l.append(o)

Submission status: Wrong Answer

Solution code:
l=[]
r=[]
l.append(int(input()))
while l:
    o=int(input())
    if not o:
        r.append(l.pop())
    else:
        l.append(o)
for i in r:
    print(i)

Submission status: Wrong Answer

Solution code:
tracks = []
while 1:
    try:
        c = int(raw_input())
        if c == 0:
            print tracks.pop()
            if tracks == []:
                break
        else:
            tracks.append(c)
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
garage = []
while True:
    came = int(raw_input())
    if came == 0:
        print garage[-1]
        garage.pop(-1)
        if len(garage) == 0:
            break
    else:
        garage.append(came)

Submission status: Wrong Answer

Solution code:
from collections import deque
garage = deque()
while True:
    came = int(raw_input())
    if came == 0:
        print garage.pop()
        if len(garage) == 0:
            break
    else:
        garage.append(came)

Submission status: Wrong Answer

Solution code:
l = []
while True:
	train = int(raw_input())
	if train == 0:
		print(l.pop())
	else:
		l.append(train)
	if l == []:
		break

Submission status: Wrong Answer

Solution code:
d = []

while 1:
    n =	int(raw_input())
    if n == 0:
	print d[-1]
	d = d[:-1]
    else:
        d.append(n)

    if len(d) == 0:
	break

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
stuck = ""
for i in range(n):
    x = raw_input()
    if x == "0":
        l = len(stuck) - 1
        print stuck[l]
        stuck = stuck[:l]
    else:
        stuck += x

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
stuck = ""
count = 0
while count < n:
    x = raw_input()
    if x == "0":
        l = len(stuck) - 1
        print stuck[l]
        stuck = stuck[:l]
    else:
        stuck += x
        count += 1

Submission status: Wrong Answer

Solution code:
stuck = ""
count = 0
while True:
    try:
        x = raw_input()
        if x == "0":
            l = len(stuck) - 1
            print stuck[l]
            stuck = stuck[:l]
        else:
            stuck += x
            count += 1
    except:
        break

Submission status: Accepted

Solution code:
import sys

def run():
    cars = []
    for _n in sys.stdin:
        n = int(_n)
        if n == 0:
            print(cars.pop())
        else:
            cars.append(n)

if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
counter = -1
train = []
while True:
	try:
		x = int(input())
	except:
		break
	if x == 0 and len(train) != 0:
		print(train[counter])
		train.remove(train[counter])
		counter -= 1
	else:
		train.append(x)
		counter += 1

Submission status: Accepted

Solution code:
train = []
while True:
    try:
        n = int(raw_input())
        if n == 0:
            print train.pop()
        else:
            train.append(n)
    except:
        break

Submission status: Accepted

Solution code:
st = []
while 1:
    try:
        x = int(input())
        st.append(x) if x != 0 else print(st.pop())
    except EOFError:
        break

Submission status: Accepted

Solution code:

stack = []

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

pile = []

while True:
    try:
        num = int(input())
        if num != 0:
            pile.append(num)
        else:
            print(pile[-1])
            pile.pop(-1)
    except:
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
lis = []
for s in sys.stdin:
  d = int(s)
  if d == 0:
    print lis[-1]
    lis.pop()
  else:
    lis.append(d)

Submission status: Accepted

Solution code:
lis=[]
cnt=0

while True:
    try:
        n=int(input())
        if n:
            cnt+=1
            lis.append(n)
        else:
            print(lis.pop(cnt-1))
            cnt-=1

    except:
        break

Submission status: Accepted

Solution code:
import sys

cars = []
for line in sys.stdin:
    car = int(line)
    if car:
        cars.append(car)
    else:
        print(cars.pop())

Submission status: Accepted

Solution code:
stack = list()
while (True):
    try:
        s = int(input())
    except EOFError:
        break;
    if s == 0:
        print(stack.pop())
    else:
        stack.append(s)

Submission status: Accepted

Solution code:
ls = []
while 1:
    try:
        n = int(raw_input())
    except EOFError:
        break
    if n!=0:
        ls.append(n)
    else:
        print ls[-1]
        del ls[-1]

Submission status: Accepted

Solution code:
import sys
Rail = []
for S in sys.stdin:
    S=int(S)
    if S!=0:
        Rail.append(S)
    else:
        print Rail.pop()

Submission status: Accepted

Solution code:
in_ = []
out = []
try:
	while 1:
		in_.append(raw_input())
		if in_[-1] == "0":
			in_.pop()
			out.append(in_.pop())
except:
	pass

for i in out:
	print(i)

Submission status: Accepted

Solution code:
ls = []
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break
    if n != 0:
    	ls.append(n)
    else:
    	print ls.pop()

Submission status: Accepted

Solution code:
import sys
s=[]
for l in sys.stdin:
	n=int(l)
	if n==0:print s.pop()
	else:s.append(n)

Submission status: Accepted

Solution code:
import sys
s=[]
for n in map(int,sys.stdin):
	if n==0:print s.pop()
	else:s.append(n)

Submission status: Accepted

Solution code:
def get_input():
    while True:
        try:
            yield raw_input()
        except EOFError:
            break

num_lis = list(get_input())

train_lis = []
for num in num_lis:
    if num == '0':
        print(train_lis[0])
        del train_lis[0]
    else:
        train_lis.insert(0, num)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys
import math

railroad = []
outCar = []

for data in sys.stdin:
    data = int(data)
    if data != 0:
        railroad.append(data)
    else:
        outCar.append(railroad.pop())

for data in outCar:
    print(data)

Submission status: Accepted

Solution code:
import sys
cars = []
out_cars = []
cars_size = 0
for line in sys.stdin:
    n = int(line)
    if n == 0:
        out_cars.append(cars.pop(cars_size - 1))
        cars_size -= 1
    else:
        cars.append(n)
        cars_size += 1
[print(car) for car in out_cars]

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys


def main():
    stack = []
    for a in sys.stdin.read().split("\n"):
        if a == "0":
            print(stack.pop())
        else:
            stack.append(a)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

def main():
    LIST=[]
    while True:
        try:
            IN=int(input())
            if IN==0:
                print(LIST[len(LIST)-1])
                del LIST[len(LIST)-1]
            else:
                LIST.append(IN)

        except:
            break
            
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
l = []
for i in sys.stdin.readlines():
  if int(i) == 0:
    print(l.pop())
  else:
    l.append(int(i))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
res = []
while True:
	try:
		n = input()
		if n == 0:
			print res[len(res)-1]
			res = res[:-1]
		else:
			res.append(n)
	except EOFError:
		break

Submission status: Accepted

Solution code:
import sys
x=[]
u=[]
for line in sys.stdin.readlines():
    y=int(line)
    if(y!=0):
        x.append(y)
    else:
         u.append(x.pop(-1))
for i in range(len(u)):
    print(u[i])

Submission status: Accepted

Solution code:
import sys

lines = sys.stdin.readlines()
queue = []
for line in lines:
    if int(line)>0:
        queue.append(int(line))
    elif int(line)==0:
        print (queue[-1])
        queue.pop(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
try:
  rail = []
  while True:
    n = int(raw_input())
    if n != 0:
      rail.append(n)
    else:
      print rail.pop()
except:
  pass

Submission status: Accepted

Solution code:
import sys
carslist = []
anslist = []
for line in sys.stdin:
    n = int(line)
    if n == 0:
        anslist.append(carslist.pop())
    else:
        carslist.append(n)
for ans in anslist:
    print ans

Submission status: Accepted

Solution code:
import sys
cars = []
for line in sys.stdin:
    car = int(line)
    if car:
        cars.append(car)
    else:
        print(cars.pop())

Submission status: Accepted

Solution code:
import sys
stk = []
ans = []
for i in sys.stdin:
    if(int(i)==0):
        ans.append(stk.pop())
    else:
        stk.append(int(i))
print('\n'.join(map(str,ans)))

Submission status: Accepted

Solution code:
#encoding=utf-8

stac, car_in, ans = [], [], []
while True:
    try:
        stac.append(input())
    except:
        break

z = len(stac)
for i in xrange(z):
    if stac[i] != 0:
        car_in.insert(0,stac[i])
    elif stac[i] == 0:
        ans.append(car_in[0])
        del car_in[0]

for i in xrange(len(ans)):
    print ans[i]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stack = []
for line in sys.stdin:
    a = int(line)
    if a == 0:
        print(stack.pop())
    else:
        stack.append(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

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

Submission status: Accepted

Solution code:
import sys
orders = sys.stdin.readlines()
stack = []
for order in orders:
    if order == '0\n':
        print(stack.pop(), end = '')
    else:
        stack.append(order)

Submission status: Accepted

Solution code:
li = []
while True:
    try:
        x = int(input())
    except:
        break

    if x == 0:
        print(li.pop())
    else:
        li.append(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = []
while True:
    try:
        s = int(input())
    except:
        break

    if s != 0:
        a.append(s)
    else:
        print(a.pop())

Submission status: Accepted

Solution code:
import sys

lst = [int(line) for line in sys.stdin.readlines()]

queue = []

for num in lst:
    if num != 0:
        queue.append(num)
    else:
        print(queue[-1])
        del queue[-1]

Submission status: Accepted

Solution code:
try:
    l = []
    while 1:
        d = int(input())
        if d:
            l.append(d)
        else:
            print(l.pop())
except:
    pass

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stack = []
for i in sys.stdin:
    try:
        a = int(i)
        if a > 0:
            stack.append(a)
        else:
            print stack.pop()
    except:
        pass

Submission status: Accepted

Solution code:
stack = []

while True:

  try:
    s = int(raw_input())

    if s == 0:
      print stack.pop()

    else:
      stack.append(s)

  except EOFError:
    break

Submission status: Accepted

Solution code:
stack = list()
while True:
	try:
		num = eval(input())
		if num != 0:
			stack.append(num)
		else:
			print(stack.pop())
	except EOFError:
		break

Submission status: Accepted

Solution code:
cars = []
while True:
    try:
        num = int(input())
    except:
        break
    if num == 0:
        print(cars[-1])
        cars[-1:] = []
    else:
        cars.append(num)

Submission status: Accepted

Solution code:
import sys

a = []
for i in sys.stdin.readlines():
    n = i[:-1]
    if n == '0':
        print(a.pop())
    else:
        a.append(n)

Submission status: Accepted

Solution code:
rail = []
while 1:
    try:
        n = input()
        if n > 0: rail.append(n)
        else: print rail.pop()
    except:
        break

Submission status: Accepted

Solution code:
import sys
import sys

a = []
for line in sys.stdin:
    a.append(line)

lis=[]
for n in a:
    inp=int(n)
    if inp==0:
        print lis[-1]
        del lis[-1]
    else:
        lis.append(inp)

Submission status: Accepted

Solution code:
# coding: utf-8
L=[]
while True:
    try:
        n=int(input())
        if n==0:
            print(L[-1])
            L.pop()
        else:
            L.append(n)
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys
s=[]
while True:
    try:
        n=int(input())
    except:
        sys.exit()
    if n==0:
        print(s.pop())
    else:
        s.append(n)

Submission status: Accepted

Solution code:
import sys
num_li = []
for line in sys.stdin:
    if int(line)==0: print(num_li.pop())
    else: num_li.append(int(line))

Submission status: Accepted

Solution code:
import sys

s = []
for line in sys.stdin:
    if line.rstrip() == '0':
        print s.pop()
    else:
        s.append(line.rstrip())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
Num = []
while True:
    try:
        n = int(input())
        if n != 0:
            Num.append(n)
        elif n == 0:
            print(Num.pop())
    except EOFError:
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque


if __name__ == '__main__':
    s = deque()  # ?????????????????¢???????????¨?????????????????\??£???????????????append()??????????????????????????????pop()
    # ??????????????\?????¨???????????????
    for line in sys.stdin:
        if line.strip() == '0':
            print(s.pop())
        else:
            s.append(line.strip())

Submission status: Accepted

Solution code:
cars = []
gone = []
while True:
    try:
        c = int(input())
        if c != 0:
            cars.append(c)
        else:
            gone.append(cars.pop())
    except:
        break
print('\n'.join(map(str, gone)))

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

stack = []

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

Submission status: Accepted

Solution code:
tracks=[]
while True:
    try:
        s=int(input())
        if s==0:
            print(tracks.pop())
        else:
            tracks.append(s)
    except:
        break

Submission status: Accepted

Solution code:
import sys
a=[]
stack=[]
for line in sys.stdin:
    a.append(int(line))
for i in range(len(a)):
    if a[i]==0:
        print(stack[-1])
        del stack[-1]
    else:stack.append(a[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
array = []
while True:
    try:
        n = int(input())
        array.append(n)
    except EOFError:
        break
data = []
for i in range(len(array)):
    if array[i] == 0:
        elm = data.pop()
        print(elm)
    else:
        data.append(array[i])

Submission status: Accepted

Solution code:
import sys

cars = []

while True:
  n = sys.stdin.readline()
  if not n: break
  n = int(n.rstrip())
  if n == 0:
    print(cars.pop())
  else:
    cars.append(n)

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
array = []
array2 = []
import sys
for i in sys.stdin.readlines():
    n = i.rstrip()
    if n == "0":
        array2.append(array[-1])
        array.pop(-1)
    else:
        array.append(n)
for i in range(len(array2)):
    print(array2[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math as mas

a=[]
for t in sys.stdin:
	i=int(t)
	if i:a.append(i)
	else:
		print(a[-1])
		a.pop()

#for i in sys.stdin:
#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

stack = []
for s in sys.stdin:
    v = int(s)
    if v == 0:
        print(stack.pop())
    else:
        stack.append(v)

Submission status: Accepted

Solution code:
from sys import stdin
from collections import deque
box = deque()
for _, train in enumerate(stdin) :
    if train.strip() != '0' : box.append(train.strip())
    else : print(box.pop())

Submission status: Accepted

Solution code:
list = []
while True:
    try:
        num = int(input())
        if num == 0:
            print(list.pop())
        else:
            list.append(num)
    except:
        break

Submission status: Accepted

Solution code:
import sys


shako = []

s = sys.stdin.read().strip().split("\n")

for i in s:
    if i != "0":
        # print("appended",i)
        shako.append(i)
        # print(shako)
    else:
        print(shako.pop())

Submission status: Accepted

Solution code:
import sys
l = []
for line in sys.stdin:
    v = int(line)
    if v != 0:
        l.append(v)
    else:
        print(l.pop())

Submission status: Accepted

Solution code:
from sys import stdin
stack = []
for line in stdin:
    line = int(line)
    if line == 0:
        print(stack.pop(0))
    else:
        stack.insert(0,line)

Submission status: Accepted

Solution code:
import sys

cars = []
for i in sys.stdin:
    if int(i) == 0:
        print(cars.pop())
    else:
        cars.append(int(i))

Submission status: Accepted

Solution code:
import fileinput
a = []
for n in fileinput.input():
    n = int(n)
    if n == 0:
        print(a.pop())
    else:
        a.append(n)

Submission status: Accepted

Solution code:
import sys
cars = []
num = -1

for user in sys.stdin:
    i = int(user)
    if i == 0:
        print(cars[num])
        cars.pop(num)
        num -= 1
    else:
        cars.append(i)
        num += 1

Submission status: Accepted

Solution code:
tracks = []
while True:
    try:
        c_num = int(input())
    except:
        break
    if c_num == 0:
        print(tracks.pop())
    else:
        tracks.append(c_num)

Submission status: Accepted

Solution code:
import sys
def main():
    a = []
    for line in sys.stdin:
        hoge = int(line)
        if hoge != 0:
            a.append(hoge)
        elif hoge == 0:
            print(a.pop(-1))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# Aizu Problem 0013: Switching Railroad Cars
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


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

Submission status: Accepted

Solution code:
stack=[]
i=0
x=int(input())
stack.append(x)
while 1:
    try:
        x=int(input())
        if (x==0):
            print(stack[i])
            stack.pop()
            i-=1
        else:
            stack.append(x)
            i+=1
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys
data = []
for l in sys.stdin:
    l = int(l)
    if l == 0:
        print(data.pop())
    else:
        data.append(l)

Submission status: Accepted

Solution code:
import sys

d = sys.stdin.readline().rstrip()
stack = list()
while d:
    if d != '0':
        stack.append(d)
    else:
        print(stack.pop())
    d = sys.stdin.readline().rstrip()

Submission status: Accepted

Solution code:
import sys
if __name__ == '__main__':
    a = []
    for tmpLine in sys.stdin:
        x = (int)(tmpLine)
        if x != 0:
            a.append(x)
        else:
            print(a.pop())

Submission status: Accepted

Solution code:
t = 0
numbers = []
while t == 0:
    try:
        number = int(input())
    except:
        break
    else:
        if number == 0:
            print(numbers[-1])
            numbers.pop(-1)
        else:
            numbers.append(number)

Submission status: Accepted

Solution code:
# coding=utf-8


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

Submission status: Accepted

Solution code:
# coding:utf-8

syako = []
try:
    while True:
        number = int(raw_input())
        if number != 0:
            syako.append(number)
        elif number == 0:
            print syako.pop()
except:
    pass

Submission status: Accepted

Solution code:
arr = []

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

    if n == 0:
        print(arr[-1])
        arr = arr[:-1]
    else:
        arr.append(n)

Submission status: Accepted

Solution code:
def main():
    _Stack = []
    while True:
        try:
            n = int(input())
            if n == 0:
                print(_Stack.pop())
                continue
            else:
                _Stack.append(n)
        except EOFError:
            break
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

stack = []

for line in sys.stdin:
  try:
    train = int(line)
    if train == 0:
      print(stack.pop())
    else:
      stack.append(train)
  except:
    break

Submission status: Accepted

Solution code:
import sys

s = []

for i in map(int, sys.stdin):
    if i:
        s.insert(len(s), i)
    else:
        print(s.pop())

Submission status: Accepted

Solution code:
i= 0
a,b = [],[]

while True:
    try:
        a.append(int(raw_input()))

        if a[i] == 0:
            b.append(a[i-1])
            a.pop()
            print a[i-1]
            a.pop()
            i -=1
        else:
            i +=1

    except:
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

class Stack(object):
	maxnum = 100
	array = []
	for i in range(100):
		array.append(0)
	index = 0
	def push(self, data):
		self.array[self.index] = data
		self.index += 1
	def pop(self):
		print(self.array[self.index-1])
		self.index -= 1

road = Stack()
while True:
	try:
		num = int(raw_input())
		if num != 0:
			road.push(num)
		else:
			road.pop()
	except EOFError:
		break

Submission status: Accepted

Solution code:
stack = []
while True:
    try:
        num = int(input())
    except:
        break
    if num == 0:
        print(stack.pop())
    else:
        stack.append(num)