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 <iostream>
#include <stack>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    stack<int> s;
    while (cin >> n) {
        if (n == 0) {
            cout << s.top() << "\n";
            s.pop();
        } else {
            s.push(n);
        }
    }
    return 0;
}

C++: #include<stdio.h>
int main(){
  int sp=0,data[100],n;
  while(1){
    scanf("%d",&n);
    if(n==0){
      sp--;
      printf("%d\n",data[sp]);
    }else{
      data[sp]=n;
      sp++;
    }
  }
}

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

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

  return 0;
}

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

int main(){
	int a[100]={0};int n=0;
	while(cin>>a[n++]);n--;
	int b[10]={0};
	for(int i=0;i<n;i++)
	{
		if(a[i]==0)
		{
			cout<<b[0]<<endl;
			for(int j=0;j<9;j++)
			{
				b[j]=b[j+1];
			}
		}else
		{
			for(int j=9;j>0;j--)
			{
				b[j]=b[j-1];
			}
			b[0]=a[i];
		}
	}
	return 0;
}

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

stack<int> st;

int main() {
	
	int m, tmp;
	
			while (cin >> m){
			
				if(m > 0)  {
					st.push(m);
				}
				else if(m == 0)  {
					cout << st.top() << endl;
					st.pop();
				}
			}
			
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
    int train[10]={0},n,count=0,outTrain[10],trainCount=0;
    while(cin >> n){
        if(cin.eof())break;
        if(n){
            for(int i=count ; i!=0 ; i--){
                train[i]=train[i-1];
            }
            train[0]=n;
            count++;
        }
        else{
            outTrain[trainCount]=train[0];
            cout << train[0] << '\n';
            for(int i=0 ; i<count ; i++){
                train[i]=train[i+1];
            }
            train[count]=0;
            count--;
            trainCount++;
        }
    }
    return 0;
}

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

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

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

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

	while(scanf("%d", &x) != EOF){
		if(x != 0){
			st.push(x);
		}else{
			printf("%d\n", st.top());
			st.pop();
		}
	}

	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	stack<int> st;
	int x;
	while (cin >> x) {
		if (x == 0) {
			cout << st.top() << endl; st.pop();
		}
		else st.push(x);
	}
}

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

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  vector<int> stack;
  int input;
  while (cin >> input) {
    if (input == 0) {
      cout << stack.back() << endl;
      stack.pop_back();
    } else {
      stack.push_back(input);
    }
  }
}

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


int main()
{
    std::stack<int> Stack;
    while(true){
        int n;
        std::cin >> n;
        if(std::cin.eof()) break;
        if(n == 0){
            assert(Stack.empty() == false);
            std::cout << Stack.top() << std::endl;
            Stack.pop();
        }else{
            Stack.push(n);
        }
    }
    return 0;
}

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

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

using namespace std;       
int main(){
  stack<int> s;
  int a;
  while(cin >> a){
    if(a != 0){
      s.push(a);
    }else if(s.size() == 0){
      break;    
    }else{
      cout << s.top()<< endl;
      s.pop();
    }
  }
  return 0;
}

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

int main()
{
  stack<int> trains;
  int i;
  do
  {
    cin >> i;
    if (i != 0) trains.push(i);
    else
    {
      cout << trains.top() << endl;
      trains.pop();
    }
  } while (true);//!trains.empty());
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
#include <stack>
using namespace std;
 
const int MAX= 10000100;

#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()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

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

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

int main(void){
	double n;
	stack <double> buf;

	while (true){
		cin>>n;
		if (cin.eof()) break;

		if (n!=0) buf.push(n);
		else{
			cout<<buf.top()<<endl;
			buf.pop();
		}
	}
    return 0;
}

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

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

int main(){

	int a;
	int i = -1, j = -1;
	std::vector<int> array1;
	std::vector<int> array2;


	while(std::cin >> a){
		if(a != 0){
			array1.push_back(a);
			i++;
		}else{
			array2.push_back(array1[i--]);
			array1.pop_back();
			j++;
		}
	}
	
	for(i=0;i<=j;i++){
		std::cout << array2[i] <<  std::endl;
	}
}

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

int main()
{
	int train[10000],i=0;
	while(1){
		cin>>train[i];
		if(train[i]==0){
			i--;
			cout<<train[i]<<endl;
		}else{
			i++;
		}
	}
}

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

int main(){
	std::deque<int> que;
	int tmp;
	while(std::cin >> tmp){
		if(tmp == 0) std::cout << que.pop() << std::endl;
		else que.push(tmp);
	}
		return 0;
	}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int in;
	vector <int> a;
	while (1) {
		cin >> in;
		if (in == 0) {
			cout << a[a.size() - 1];
			a.erase(a.end());
			if (a.size() == 0)
				break;
			else
				cout << endl;
		}
		else
			a.push_back(in);
	}
	return 0;
}