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

C++: #include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>

using namespace std;


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

  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int train[10000],moving,situation=0,ans[10000],n=0,ende=0;
    while(cin>>moving){
        if(moving!=0){
            train[situation]=moving;
            situation++;
        }
        else {
                situation--;
                ans[ende]=train[situation];
                ende++;
        }
    }
    for(int i=0;i<ende;i++)cout<<ans[i]<<endl;

}

C++: #include <bits/stdc++.h>
using namespace std;

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

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

C++: #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
  int car[10],car2[10]={0};
  stack<int> rail;
  int i=0;
  while(cin >> car[i]){
    if(car[i] != 0){
      rail.push(car[i]);
	}
    else{
      cout << rail.top();
      rail.pop();
    }
    i++;
  }
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int train[10]={0},n,count=0,outTrain[10],trainCount=0;
    while(scanf("%d",&n)!=EOF){
        if(n){
            for(int i=count ; i!=0 ; i--){
                train[i]=train[i-1];
            }
            train[0]=n;
            count++;
        }
        else{
            outTrain[trainCount]=train[0];
            for(int i=0 ; i<count ; i++){
                train[i]=train[i+1];
            }
            train[count]=0;
            count--;
            trainCount++;
        }
    }
    for(int i=0 ; i<trainCount ; i++){
        cout << outTrain[i] << '\n';
    }
    return 0;
}

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

int main()
{
	int car[10],order[100],i,j,k=0;
	
	for(i=0; i<10; i++){car[i]=0;}
	i=0;
	while((scanf("%d",&order[i]))!=EOF){i++;}
	for(j=0; j<i; j++){
		if(order[j]!=0){
			car[k]=order[j];
			k++;
		}else{
			k--;
			cout << car[k] << endl;
			car[k]=0;
		}
	}
}

C++: #include <stdio.h>

int main() {
	int a,i,k,m;
	int data[15] = {0};
	int output[15] = {0};
	for (i = 0; i < 15; i++) {
		scanf("%d", &a);
		if (a != 0) {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					data[k] = a;
					break;
				}
			}
		}
		else {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					for (m = 0; m < 15; m++) {
						if (output[m] == 0) {
							output[m] = data[k - 1];
							break;
						}
					}
					data[k - 1] = 0;
					break;
				}
			}
		}
		if (data[0] == 0) {
			break;
		}
	}
	printf("\n");
	for (i = 0; i < 15; i++) {
		if (output[i] != 0) {
			printf("%d\n", output[i]);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(void) {
	stack<int>s;
	int n;
	while (cin >> n) {
		if (n == 0) {
			cout << s.top() << endl;
			s.pop();
		}
		else {
			s.push(n);
		}
	}
	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>

using namespace std;

int main(){
  short stack[10]={0},turn[10]={0};
  short *pstack=stack,*pturn=turn;
  while(1){
    int num;
    cin>>num;
    if(num){
      *pstack=num;
      pstack++;
    }else{
      pstack--;
      *pturn=*pstack;
      pturn++;
    }
    if(pstack==stack) break;
  }
  for(int i=0;turn[i];i++){
    if(i!=0)cout<<endl;
    cout<<turn[i];
  }
}

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

stack<int> s;
int n;

int main(){
	while(cin>>n){
		if(n==0) {
			cout<<("%d\n",s.top())<<endl;
			s.pop();
		}
		else{
			s.push(n);
		}
	}
	return 0;
}

C++: //#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
constexpr void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    int n;
    stack<int> st;
    while(cin>>n) {
        if(n==0){
            P(st.top());
            st.pop();
        }
        else st.push(n);
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
#define int long long
signed main(){
	stack<int> q;
	int a;
	while( scanf("%lld", &a) != EOF ){
		if(a==0){ cout << q.top() << endl; q.pop();}
		else q.push(a);
	}
	return 0;
}

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

using namespace std;

void Solution()
{
    stack <int> car;
    
    int n;
    
    while (cin>>n)
    {
        if(n == 0)
        {
            cout<<car.top()<<endl;
            car.pop(); //Removes the element on top of the stack
        }
        else
        {
            car.push(n);
        }

    }

    return;
}

int main()
{
    Solution();
    return 0;
}