Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Railway struct {
	trains trains
}

type trains []int

func main() {
	var stdin string
	var s = bufio.NewScanner(os.Stdin)

	railway := Railway{}
	for s.Scan() {
		stdin = s.Text()

		n, err := strconv.Atoi(stdin)
		if err != nil {
			continue
		}
		railway.lifo(n)
	}
}

func (r *Railway) lifo(n int) {
	if n == 0 {
		if len(r.trains) == 0 {
			return
		}
		fmt.Println(r.trains[len(r.trains)-1])
		r.trains = r.trains[:len(r.trains)-1]
	} else {
		r.trains = append(r.trains, n)
	}
}

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

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

for i in l2:
    print(i)

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

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

Python: 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)

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

Python: l = []
while True:
	try:
		train = int(raw_input())
		if train == 0:
			print(l.pop())
		else:
			l.append(train)
	except EOFError:
		break

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

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

Python: import sys

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

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

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

Python: import sys
a=[]
for e in map(int,sys.stdin):a.append(e)if e else print(a.pop())

Python: if __name__ == '__main__':

	A = []

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

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

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

C++: #include <iostream>
#include <stack>
#include <vector>
using namespace std;

int main()
{
	stack<int> car;
	vector<int> outlist;

	while( !car.empty() || outlist.empty() )
	{
		int carnum;
		cin >> carnum;
		if(carnum)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}
	
	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
	cout << '\n';
}

C++: #include <cstdio>
#include <stack>
using namespace std;

int main()
{
        int car;
        stack<int> st;
        while(scanf("%d", &car) != EOF) {
                if(car == 0) {
                        if(!st.empty()) {
                                printf("%d\n",st.top());
                                st.pop();
                        }
                } else {
                        st.push(car);
                }
        }
        return 0;
}

C++: 
#include <iostream>
#include <stack>

int main(){
    std::stack<int> rail;
    int buf;
    
    // repeat until "cin" fails.
    while (std::cin >> buf) {
        if (buf == 0) { // train goes out.
            std::cout << rail.top();
            rail.pop();
        }
        else{   // train comes in.
            rail.push(buf);
        }
    }
    
    return 0;
}

C++: #include<stdio.h>
#include<stack>

int main(){
	int data[100],i=0,n=0;
	std::stack<int> train;
	while(scanf("%d",&data[i])!= EOF){
		i++;n++;
	}
	i=0;
	train.push(data[i]);
	for(i=1;i<n;i++){
		if(data[i]==0){
			printf("%d\n",train.top());
			train.pop();
		}else{
			train.push(data[i]);
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <stack>

int main(int argc, char *argv[]) {
	using namespace std;
	
	int rcv;
	stack<int> trains;
	while (EOF != fscanf(stdin, "%d", &rcv)) {
		if (rcv != 0) {
			trains.push(rcv);
		}
		else {
			printf("%d\n", trains.top());
			trains.pop();
		}
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;

int main() {
  stack<int> s;
  int n;
  while (cin >> n) {
    if (n == 0) {
      cout << s.top() << endl;
      s.pop();
    } else {
      s.push(n);
    }
  }
}

C++: #include <iostream>
#include <stack>
using namespace std;

int main(){
  stack<int> st;
  int x;

  while(cin >> x){
    if(x == 0){
      cout << st.top() << endl;
      st.pop();
    }
    else{
      st.push(x);
    }
  }
}

C++: #include <iostream>
#include <stack>
using namespace std;

int main(){
	stack<int> st;
	int n, a;

	while(cin >> n){
		if(n!=0){
			st.push( n );
		}else{
			a = st.top();
			cout << a << endl;
			st.pop();
		}
	}
}

C++: #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;

stack<int> sta;

int main()
{
  int a;
  while(1){
    cin>>a;
    if(a)
      sta.push(a);
    else{
      cout<<sta.top()<<endl;
      sta.pop();
    }
  }
  return 0;

}

C++: #include　<iostream>
#include <array>

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num==0) pop();
		else push(num);
	}

    return 0;
}

C++: #include <stdio.h>

int main(void){
	int t,s=0;
	
	while(scanf("%d",&t),t){
		int i,now=0,count=0;
		int train[12]={0},car[12]={0};
		
		
		for(;;){
			if(s!=0){
				scanf("%d",&t);
			}
			else {
				s=1;
			}
			if(t!=0){
				train[now]=t;
				now++;
			}
			else{
				now--;
				car[count]=train[now];
				train[now]=0;
				count++;
				if(now==0)break;
			}
		}
		
		i=0;
		while(car[i]!=0){
			printf("%d\n",car[i]);
			i++;
		}
		s=0;
	}
	return 0;
}

C++: #include <iostream>
#include <stack>

using namespace std;

int main(void){

  int n;
  stack <int> s;
  while( cin >> n ){
    if(n) s.push(n);
    else {
      cout << s.top() << endl;
      s.pop();
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int main(){
    int n;
    stack<int> st;
    while(cin >> n){
        if(n == 0){
            cout << st.top() << endl;
            st.pop();
        }
        else {
            st.push(n);
        }
    }
    return 0;
}

C++: #include<iostream>
int main(){int a,c=0,s[9999];while(std::cin>>a){if(a!=0)s[c++]=a;else std::cout<<s[--c]<<"\n";}}

C++: #include<iostream>
#include<stack>
using namespace std;

int main(){
	int x;
	stack<int> S;
	while(1){
		cin>>x;
		if(x==0){
			if(S.empty())break;
			cout<<S.top()<<endl;
			S.pop();
		}else{
			S.push(x);
		}
	}
	return 0;
}