Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	n, err := strconv.Atoi(nextString())
	return n, err
}

func main() {
	scanner.Split(bufio.ScanWords)

	stack := []int{}
	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		if n == 0 { // pop
			fmt.Println(stack[len(stack)-1])
			stack = stack[0:(len(stack) - 1)]
		} else { // push
			stack = append(stack, n)
		}
	}
}

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

int main() {
	int x;
	deque<int> st;
	while (cin >> x) {
		if (x == 0) {
			cout << st.back() << endl;
			st.pop_back();
		}
		else {
			st.push_back(x);
		}
	}
	return 0;
}

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

int main()
{
    int n;
    int stack[10];
    int index=0;
    vector<int> r;
    while (scanf("%d",&n) != EOF)
    {
	if (n!=0)
	{
	    stack[index] = n;
	    index++;
	} else {
	    r.push_back(stack[index-1]);
	    index--;
	}
    }
    for (int i=0; i<r.size(); i++)
    {
	cout << r[i] << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int main(){
	int car[10]={0,0,0,0,0,0,0,0,0,0};
	int a,c=0;
	
	while(~scanf("%d",&a)){
		if(a==0){
			c--;
			printf("%d",car[c]);
		}
		else {
			car[c]=a;
			c++;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main(){
    vector<int> array;
    int i = -1;
    while(cin >> i){
        if(i == 0){
            cout << array[array.size()-1]<< endl;
            array.pop_back();
        }else 
            array.push_back(i);
    }
    return 0;
}

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

using namespace std;

stack<int>s;

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

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 <bits/stdc++.h>
#define rep(i,l,n) for(i=l;i<n;i++)
using namespace std;

int main(){
	int data[15]={},i=0,n;

	while(scanf("%d",&n)!=EOF){
		if(n!=0){
			data[i]=n;
			i++;
		}else if(n==0){
			cout<<data[i-1]<<endl;
			i--;
		}
	}
}

C++: 
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	vector<int> train;
	int a;
	while (true) {
		cin >> a;
		if (a == 0) {
			cout << train.back() << endl;
			train.pop_back();
		}
		else {
			train.emplace_back(a);
		}
	}
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

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

    return 0;
}

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

using namespace std;

int main(){

  int train;
  stack<int> s;

  cin >> train;

  s.push(train);

  while(!s.empty()){

    cin >> train;

    if(train) s.push(train);
    else {
      cout << s.top() << endl;
      s.pop();
    }

  }

}

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

int main(){
    int n;
    int i=0;
    int s=55;
    int num[105];
    while(cin>>n){
        if(n==0){
            while(1){
                if(num[s]!=0){
                    cout<<num[s]<<endl;
                    num[s]=0;
                    s=55;
                    break;
                }
                s--;
            }

        }
        else {
            while(1){
                if(num[i]==0){
                    num[i]=n;
                    i=0;
                    break;
                }
                i++;
            }
        }
                }
    return 0;
    }

C++: #include <iostream>
#include <stack>
int main(){
  std::stack<int> i;
  int n=0;
  while(std::cin>>n){
    if(!n)std::cout<<i.top()<<std::endl,i.pop();
    else{i.push(n);}
  }
  return 0;
}

C++: #include <stdio.h>
int main(){
    int stay[10];
    int out[100];
    int i=0, k=0, j=0,n;
    while(scanf("%d",&n) != EOF){
        if(n==0){
            out[k]=stay[i-1];
            i--;
            k++;
        }else{
            stay[i]=n;
            i++;
        }
    }
    for(j=0;j<k;j++){
        printf("%d?\n",out[j]);
    }
    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main() {
  stack<int> track;
  int n;
  while (cin >> n) {
    if (n == 0) {
      cout << track.top() << endl;
      track.pop();
      continue;
    }
    track.push(n);
  }
}

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

int main ()
{
    std::stack<u_int> cars;
    u_int number;

    while(std::cin >> number){
        if(number != 0){
            cars.push(number);
        }else{
            std::cout << cars.top() << std::endl;
            cars.pop();
        }
    }
    
    return 0;
}

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

using namespace std;

int main(){
	vector<int> stack, seq;
	int n;

	while(cin >> n){
		if(cin.eof()){
			break;
		}
		if(n == 0){
			seq.push_back(stack.back());
			stack.pop_back();
		}else{
			stack.push_back(n);
		}
	}
	for(int& n : seq){
		cout << n << endl;
	}
}

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

using namespace std;

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

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

    return 0;
}

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



int main()
{
stack<int> a;
int d;

while(cin>>d){

if(d!=0) {
a.push(d);
}
else {
cout<<a.top()<<endl;
a.pop();
}
}

}

C++: #include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<stack>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

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

  }
}