Go: package main

import "fmt"

func main() {
	var i int
	stack := make([]int, 0)
	for {
		v, _ := fmt.Scan(&i)
		// fmt.Println(stack)
		// println(v)
		if v == 0 {
			break
		}
		if i == 0 {
			fmt.Println(stack[len(stack)-1])
			stack = stack[:len(stack)-1]
			continue
		}
		stack = append(stack, i)
	}
}

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;
}

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

using namespace std;

int main(int argc, char const *argv[]){
    int input; 
    stack<int> train_stack;
    vector<int> order;

    cin>>input;
    train_stack.push(input);
    while (1){
        cin>>input;
        if (input==0){
            cout<<train_stack.top()<<endl;
            train_stack.pop();
        }
        else{
            train_stack.push(input);
        }
    }

    return 0;
}

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

std::stack<int> s;

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

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

int main()
{
	int n;
	vector<int> cars;
	while (cin >> n) {
		if (n==0)  {
			cout << cars.back() << endl;
			cars.pop_back();
		}
		else
			cars.push_back(n);
	}

	return 0;
}

C++: #include <stack>
#include <iostream>
using namespace std;
int main()
{
	stack<int> data;
	int input;
	
	while (cin >> input)
	{
		if (input)
		{
			data.push(input);
		}
		else
		{
			cout << data.top() << endl;
			data.pop();
		}
	}
}