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 <vector>
using namespace std;

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

	return 0;
}

C++: #include<stdio.h>

int main()
{
	int x[100]={0},y[100]={0},z,n,t=0,r=0;
	while(scanf("%d",&n) !=EOF)
	{
		if(n>=1)
		{
			x[t]=n;
			t++;
		}
		else if(n==0)
		{
			t--;
			y[r]=x[t];
			r++;
		}
	}
	
	for(z=0;z<r;z++)
	{
		printf("%d\n",y[z]);
	}
	return 0;
}

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++: #include <iostream>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    int st[100];
    int sn=0;
    while(cin>>t){
        if(t==0) cout<<st[--sn]<<'\n';
        else st[sn++]=t;
    }
    return 0;
}

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

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

C++: #include <stdio.h>

int main()
{
int p[10]={};
int x,i;
i=0;x=0;
while(scanf("%d",&x)!=EOF)
{
if(x%10>0){p[i]=x;i++;}
else{i--;printf("%d\n",p[i]);}

}
return 0;
}

C++:     #include <iostream>
    #include <stack>
    #include <vector>
     
    int main() {
    int n;
    std::stack<int> stc;
    std::vector<int> ans;
     
    while (std::cin >> n) {
    if (n == 0) {
    ans.push_back(stc.top());
    stc.pop();
    } else {
    stc.push(n);
    }
    }
     
    for (auto n : ans) {
    std::cout << n << std::endl;
    }
    }

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<stack>

using namespace::std;


int main(){

  stack<int> st;
  int val = 0;
  int ans[1000] = {};
  int i = 0;
  int j = 0;

  scanf("%d", &val);
  st.push(val);

  while(!st.empty()){
    scanf("%d", &val);
    if(val == 0){
     ans[i] = st.top();
     i++;
     st.pop();
     continue;
    }
    st.push(val);
  }

  for(j = 0; j < i; j++){
    printf("%d\n", ans[j]);
  }


  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int i=0,num,a[10],b[10],x=0;
  
  while(cin>>num){
    int count=0;
    count++;
    if(num==0){
      b[x++]=a[i-1];
      i--;
    }
    else  a[i++]=num;
  }

  for(i=0;i<x;i++)
    cout<<b[i]<<endl;
  return 0;
}

C++: #include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl


int main(){
	li p;
	stack<li> stk;
	
	while(cin>>p){
		if(p>0)stk.push(p);
		else{
			cout<<stk.top()<<endl;
			stk.pop();
		}
	}
	
	return 0;
}

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

using namespace std;

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>
#include <stack>

int main()
{
	std::stack<int> st;
	int n;

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

}

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

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

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{
      cout << s.top();
      s.pop();
    }
    if(s.size() == 0)
      break;
  }
  return 0;
}

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

int main()
{
	int queue[100], input, i = 0;
	while (cin >> input) {
		if (input != 0) {
			queue[i] = input;
			++i;
		}
		else {
			--i;
			cout << queue[i] << endl;
			queue[i] = 0;
		}
	}
	return 0;
}

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

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

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

C++: #include<iostream>
using namespace std;
int b[10000000];
int main(){
  int i=0,num,a[10],x=0;
  
  while(cin>>num){
    if(num==0){
      b[x++]=a[i-1];
      i--;
    }
    else  a[i++]=num;
    if(!i)break;
  }
  
  for(i=0;i<x;i++)
    cout<<b[i]<<endl;
  return 0;
}

C++: #include <algorithm>
#include <sstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;

int main()
{
	int x;
	stack<int> S;
	while (cin >> x && x != EOF) {
		if (x == 0) {
			cout << S.top() << endl; S.pop();
		}
		else {
			S.push(x);
		}
	}
}

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

int main() {
	int in;
	vector <int> a;
	while (1) {
		cin >> in;
		if (in == 0) {
			cout << a.back();
			a.pop_back();
			if (a.size() == 0)
				break;
			else
				cout << endl;
		}
		else
			a.push_back(in);
	}
	return 0;
}

C++: #include <iostream>

int main()
{
        int s[10], p = 0;
        int i;
        while(std::cin >> i)
                if(i)
                        s[p++]=i;
                else
                        std::cout << s[--p] << std::endl;
        return 0;
}

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 <cstdio>
#include <deque>

using namespace std;

int main(){
  deque<int> st;
  int n;
  while(~scanf("%d",&n)){
    if(n){
      st.push_back(n);
    }else{
      printf("%d\n",st.back());
      st.pop_back();
    }
  }
}

C++: #include <map>
#include <string>
#include <iostream>
#include <vector>
#include <set>
#include <cstdio>
#include <stack>
#include <algorithm>

using namespace std;

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