submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s425743769
p00013
Accepted
import sys orders = sys.stdin.readlines() stack = [] for order in orders: if order == '0\n': print(stack.pop(), end = '') else: stack.append(order)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s570392058
p00013
Accepted
li = [] while True: try: x = int(input()) except: break if x == 0: print(li.pop()) else: li.append(x)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s687218260
p00013
Accepted
train=[] while 1: try: n=input() if n==0: print(train.pop()) else: train.append(n) except: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s047639059
p00013
Accepted
a = [] while True: try: s = int(input()) except: break if s != 0: a.append(s) else: print(a.pop())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s204408054
p00013
Accepted
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]
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s266201049
p00013
Accepted
try: l = [] while 1: d = int(input()) if d: l.append(d) else: print(l.pop()) except: pass
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s572526600
p00013
Accepted
a = [] while True: try: i = int(input()) except: break if i == 0: c = a.pop() print(c) else: a.append(i)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s320985777
p00013
Accepted
import sys stack = [] for i in sys.stdin: try: a = int(i) if a > 0: stack.append(a) else: print stack.pop() except: pass
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s352777268
p00013
Accepted
stack = [] while True: try: s = int(raw_input()) if s == 0: print stack.pop() else: stack.append(s) except EOFError: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s135918984
p00013
Accepted
stack = list() while True: try: num = eval(input()) if num != 0: stack.append(num) else: print(stack.pop()) except EOFError: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s192019467
p00013
Accepted
cars = [] while True: try: num = int(input()) except: break if num == 0: print(cars[-1]) cars[-1:] = [] else: cars.append(num)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s422915092
p00013
Accepted
import sys a = [] for i in sys.stdin.readlines(): n = i[:-1] if n == '0': print(a.pop()) else: a.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s538361034
p00013
Accepted
rail = [] while 1: try: n = input() if n > 0: rail.append(n) else: print rail.pop() except: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s049360517
p00013
Accepted
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)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s222976081
p00013
Accepted
# 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
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s356217526
p00013
Accepted
import sys stack = [] for line in sys.stdin: n = int(line) if n == 0: print(stack.pop()) else: stack.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s566558465
p00013
Accepted
import sys s=[] while True: try: n=int(input()) except: sys.exit() if n==0: print(s.pop()) else: s.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s074259624
p00013
Accepted
import sys num_li = [] for line in sys.stdin: if int(line)==0: print(num_li.pop()) else: num_li.append(int(line))
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s884289233
p00013
Accepted
import sys s = [] for line in sys.stdin: if line.rstrip() == '0': print s.pop() else: s.append(line.rstrip())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s955608075
p00013
Accepted
stack = [] while True: try: n = int(input()) except: break if n == 0: print(stack.pop()) else: stack.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s953677871
p00013
Accepted
Num = [] while True: try: n = int(input()) if n != 0: Num.append(n) elif n == 0: print(Num.pop()) except EOFError: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s260456816
p00013
Accepted
s = [] while True: try: n = int(input()) except EOFError: break if n == 0: print(s.pop()) else: s.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s534416113
p00013
Accepted
memory=[] while True: try: n=int(input()) except EOFError: break if n==0: print(memory.pop()) else: memory.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s378837892
p00013
Accepted
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())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s037576748
p00013
Accepted
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)))
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s354988038
p00013
Accepted
# 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
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s557609269
p00013
Accepted
tracks=[] while True: try: s=int(input()) if s==0: print(tracks.pop()) else: tracks.append(s) except: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s601840083
p00013
Accepted
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])
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s749155058
p00013
Accepted
a=[] while 1: try:n=int(input()) except:break if n:a.append(n) else:print(a.pop())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s656472286
p00013
Accepted
# -*- 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])
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s036501949
p00013
Accepted
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)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s692595662
p00013
Accepted
import sys arr = [] for line in sys.stdin: n = int(line) if n == 0: print(arr.pop()) else: arr.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s485965605
p00013
Accepted
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])
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s023838320
p00013
Accepted
buf = [] while True: try: car = int(input()) except: break if car: buf.append(car) else: print(buf.pop())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s299099783
p00013
Accepted
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))
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s420217556
p00013
Accepted
# -*- 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)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s749274382
p00013
Accepted
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())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s252183342
p00013
Accepted
list = [] while True: try: num = int(input()) if num == 0: print(list.pop()) else: list.append(num) except: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s650803158
p00013
Accepted
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())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s161326551
p00013
Accepted
import sys l = [] for line in sys.stdin: v = int(line) if v != 0: l.append(v) else: print(l.pop())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s282388337
p00013
Accepted
from sys import stdin stack = [] for line in stdin: line = int(line) if line == 0: print(stack.pop(0)) else: stack.insert(0,line)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s946926188
p00013
Accepted
import sys cars = [] for i in sys.stdin: if int(i) == 0: print(cars.pop()) else: cars.append(int(i))
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s132878702
p00013
Accepted
import fileinput a = [] for n in fileinput.input(): n = int(n) if n == 0: print(a.pop()) else: a.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s482296880
p00013
Accepted
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
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s119320604
p00013
Accepted
tracks = [] while True: try: c_num = int(input()) except: break if c_num == 0: print(tracks.pop()) else: tracks.append(c_num)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s433075509
p00013
Accepted
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()
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s351498701
p00013
Accepted
# 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)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s830657420
p00013
Accepted
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
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s746949425
p00013
Accepted
import sys data = [] for l in sys.stdin: l = int(l) if l == 0: print(data.pop()) else: data.append(l)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s502635954
p00013
Accepted
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()
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s779417799
p00013
Accepted
import sys if __name__ == '__main__': a = [] for tmpLine in sys.stdin: x = (int)(tmpLine) if x != 0: a.append(x) else: print(a.pop())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s258080880
p00013
Accepted
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)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s594501694
p00013
Accepted
# 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)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s319827203
p00013
Accepted
# 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
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s313189852
p00013
Accepted
arr = [] while True: try: n = int(input()) except: break if n == 0: print(arr[-1]) arr = arr[:-1] else: arr.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s060246655
p00013
Accepted
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()
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s167112578
p00013
Accepted
import sys stack = [] for line in sys.stdin: try: train = int(line) if train == 0: print(stack.pop()) else: stack.append(train) except: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s016297792
p00013
Accepted
import sys s = [] for i in map(int, sys.stdin): if i: s.insert(len(s), i) else: print(s.pop())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s708664948
p00013
Accepted
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
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s291667571
p00013
Accepted
stack = [] while True: try: car = int(input()) if car == 0: print(stack.pop()) else: stack.append(car) except: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s544421153
p00013
Accepted
# 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
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s134706430
p00013
Accepted
stack = [] while True: try: num = int(input()) except: break if num == 0: print(stack.pop()) else: stack.append(num)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s906586245
p00013
Accepted
def get_input(): while True: try: yield ''.join(input()) except EOFError: break N = list(get_input()) stack = [] for l in range(len(N)): a = int(N[l]) if a == 0: print(stack.pop()) #print("POP") else: #print(a) stack.append(a)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s600820063
p00013
Accepted
import sys a=[] for e in map(int,sys.stdin): a.append(e)if e else print(a.pop())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s434141259
p00013
Accepted
a=[] while 1: try:n=int(input());a.append(n)if n else print(a.pop()) except:break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s958340043
p00013
Accepted
import sys a=[] for e in map(int,sys.stdin):a.append(e)if e else print(a.pop())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s669783215
p00013
Accepted
c=[] s=[] e=[] while True: try: t=input() if not t:break except:break c.append(int(t)) for i in c: if i==0: e.append(s.pop(-1)) else: s.append(i) [print(i) for i in e]
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s546529392
p00013
Accepted
st = [] while True: try: n = int(input()) if n == 0: print(st.pop()) else: st.append(n) except EOFError: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s186146351
p00013
Accepted
li = [] while True: try: x = int(input()) except: break if x == 0: print(li.pop()) else: li.append(x)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s856427220
p00013
Accepted
import sys a=[int(i)for i in sys.stdin] b=[] for j in a: if j == 0: print(b.pop()) else: b.append(j)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s699137194
p00013
Accepted
import sys a=[int(i)for i in sys.stdin] b=[] for j in a: if j == 0: print(b.pop()) else: b.append(j)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s889791759
p00013
Accepted
import sys s = [] [print(s.pop()) if int(e) == 0 else s.append(int(e)) for e in sys.stdin]
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s648485836
p00013
Accepted
import sys queue = [] for line in sys.stdin: n = int(line) if n != 0: queue.append(n) else: print(queue.pop())
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s704643218
p00013
Accepted
import sys l=[] for line in sys.stdin: o=int(line) if not o: print(l.pop()) else: l.append(o)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s731743285
p00013
Accepted
# AOJ 0013 Switching Railroad Cars # Python3 2018.6.9 bal4u class Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def push(self, item): self.items.append(item) def pop(self): return self.items.pop() def peek(self): return self.items[len(self.items)-1] def size(self): return len(self.items) s = Stack() while True: try: a = int(input()) if a > 0: s.push(a) else: print(s.pop()) except EOFError: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s836617781
p00013
Accepted
import sys if __name__ == '__main__': stack = [] for line in sys.stdin: n = int(line) if n == 0: print(stack.pop(len(stack) - 1)) else: stack.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s424541621
p00013
Accepted
import sys lst = [] for line in sys.stdin: if line: num = line.strip() if num == "0": print(str(lst.pop()) + "") else: lst.append(num) sys.exit(0)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s826848580
p00013
Accepted
import sys lst = [] for line in sys.stdin: # if line: num = line.strip() if num == "0": print(str(lst.pop()) + "") else: lst.append(num) sys.exit(0)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s123274518
p00013
Accepted
import sys lst = [] for line in sys.stdin: num = line.strip() if num == "0": print(lst.pop() + "") else: lst.append(num) sys.exit(0)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s185962512
p00013
Accepted
import sys lst = [] for line in sys.stdin: num = line.strip() if num == "0": print lst.pop() else: lst.append(num) sys.exit(0)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s736982777
p00013
Accepted
import sys lst = [] for line in sys.stdin: num = line.strip() if num == "0": print lst.pop() else: lst.append(num)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s853909036
p00013
Accepted
import sys lst = [] for line in sys.stdin: if line.strip() : num = int(line.strip()) if num == 0: print lst.pop() else: lst.append(num)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s442893968
p00013
Accepted
import sys def clearSpace(s): s.pop() return s list=[] for i in sys.stdin: if i.strip() != '0': list.append(i.strip()) else: print list.pop()
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s904120833
p00013
Accepted
import sys list=[] for i in sys.stdin: if i.strip() != '0': list.append(i.strip()) else: print list.pop()
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s685765914
p00013
Accepted
import sys stack=[] for i in sys.stdin: try: a=int(i) if a >0 : stack.append(a) else : print stack.pop() except: pass
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s702641892
p00013
Accepted
tracks = [] while 1: try: c0 = raw_input() if c0 == '': break c = int(c0) if c == 0: print tracks.pop() else: tracks.append(c) except EOFError: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s646185020
p00013
Accepted
stack = [] def datasets(): import sys while True: s = sys.stdin.readline() if len(s) < 2: break yield int(s) for n in datasets(): if n == 0: print stack.pop() else: stack.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s060197869
p00013
Accepted
from collections import deque garage = deque() while True: try: came = int(raw_input()) if came == 0: print garage.pop() else: garage.append(came) except ValueError: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s692526933
p00013
Accepted
l = [] while True: try: train = raw_input() if train == '0': print(l.pop()) else: l.append(train) except EOFError: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s529263357
p00013
Accepted
ans = [] while True: try: a = input() if a != 0: ans.append(a) elif a == 0: print ans[-1] del ans[-1] except EOFError: break except SyntaxError: continue
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s352710407
p00013
Accepted
stack = []; while True: try: n = input(); if (n == 0): print stack.pop() else: stack.append(n); except: break;
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s786310164
p00013
Accepted
from __future__ import (division, absolute_import, print_function, unicode_literals) from sys import stdin L = [] for line in stdin: if not line.strip(): continue n = int(line) if not n: print(L.pop()) else: L.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s275335463
p00013
Accepted
bottom = [] exits = [] while True: carnum = raw_input() if carnum == '': break elif carnum == '0': exits.append(bottom[0]) del bottom[0] continue else: bottom.insert(0,int(carnum)) continue for val in exits: print val
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s742971604
p00013
Accepted
import sys #input_file = open(sys.argv[1], "r") stack = [] #for n in input_file: for n in sys.stdin: n = int(n) if n == 0: print stack.pop() else: stack.append(n)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s332131220
p00013
Accepted
list = [] while True: try: a = int(raw_input() ) if a != 0: list.append(a) else: b = list.pop() print b except EOFError: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s727174867
p00013
Accepted
x=[] while True: try: n = input() if n==0: print x.pop() else: x.append(n) except: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s385854866
p00013
Accepted
import sys s = [] for line in sys.stdin: t = int(line) if t == 0: print s.pop() else: s.append(t)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s255848205
p00013
Accepted
stack = [] while True: try: n = int(raw_input()) if n == 0: print stack.pop() else: stack.append(n) except EOFError: break
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s363210358
p00013
Accepted
#! /usr/bin/python import sys stack = [] for line in sys.stdin: #print "input = " + line.strip() num = int(line) if num == 0: pop = stack.pop() #print "pop " + str(pop) print(str(pop)) else: stack.append(num) #print "pushed " + str(num)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
s812565129
p00013
Accepted
t = [] while 1: try: a = input() except: break if a == 0: print(t[-1]) t = t[:-1] else: t.append(a)
1 6 0 8 10 0 0 0
6 10 8 1
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> 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. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> 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. </p> <p> 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. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>