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 <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#define mp make_pair
#define pii pair<int,int> 
#define ff first
#define ss second

using namespace std;

stack<int> stk;
int input;
int main()
{
	while(scanf("%d",&input)!=EOF)
	{
		if(input==0)
		{
			printf("%d\n",stk.top());
			stk.pop();
		}
		else
		{
			stk.push(input);
		}
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main() {
	int train[11] = { 0 }, junban[11] = { 0 }, a = 0, n, i;
	while (cin >> n) {
		if (n == 0) {
			for (i = 0; train[i] > 0; i++) {}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; train[i] > 0; i++) {}
			train[i] = n;
		}
	}
	for (i = 0; junban[i] > 0; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}

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

int main(){
	int n;
	int temp;
	stack<int> data;
	
	while(1){
		scanf("%d",&n);
		
		if(n!=0){
			data.push(n);
		}
		else{
			if(data.empty() == true)break;
			else{
				printf("%d\n",data.top());
				data.pop();
			}
		}
	}
	return 0;
}

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

int main(){
	int a[100];
	int i = 0;

	while (1){
		cin >> a[i];
		if (a[i] == 0){
			int j = i + 1;
			while (1){
				j--;
				if (a[j] != 0){
					cout << a[j] << endl;
					a[j] = 0;
					break;
				}
			}
		}
		i++;
	}


	return 0;
}

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

int main(){
	int n;
	stack<int> stk;
	queue<int> que;
	while(1){
		cin>>n;
		if(n==0){
			que.push(stk.top());
			stk.pop();
		}else{
			stk.push(n);
		}
		if(stk.empty())break;
	}
	while(!que.empty()){
		cout<<que.front()<<endl;
		que.pop();
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <stack>
using namespace std;
int main(){
  int n;
  stack<int> in,out;
  while(cin>>n){
    if(!n)out.push(in.top()),in.pop(),cout<<out.top()<<endl;
    else{in.push(n);}
    if(!in.size()&&out.size()>0)return 0;
  }
}

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

using namespace std;

int main() {
    vector<int> buffers;
    int buffer;

    while(cin >> buffer) {
        if(buffer == 0){
            cout << buffers[buffers.size()-1] << endl;
            buffers.pop_back();
            continue;
        }

        buffers.emplace_back(buffer);
    }
}

C++: #include<stdio.h>
#include<stack>
#include<cstdio>

using namespace std;

int main(void){

	int inp;
	stack<int> train;

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

	return 0;
}

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

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

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



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

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

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

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

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

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	stack<int> s;
	s.push(n);
	
	while(!s.empty()){
		int a;
		cin >> a;
		if(a == 0){
			cout << s.top() << endl;
			s.pop();
		}
		else {
			s.push(a);
		}
	}
	
	return 0;
}

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

int main() {
int k=0,b;
int a[1];
while(cin>>b){
	if(b!=0){
		a[k]=b;
		k=k+1;
	}
	if(b==0){
		cout<<a[k-1]<<endl;
		k=k-1;
	
}
}
	return 0;
}

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

using namespace std;

int main(){

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


	return 0;
}

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

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

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

}

C++: /*****include*****/
#include <iostream>
#include <list>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****変数置き場*****/
	list<int> V;
	int order;
	/*****処理部*****/
	while(1){
		cin >> order;
		if(order == 0){
			cout << V.back() << endl;
			V.pop_back();
		}else{
			V.push_back(order);
		}
	}
	return 0;
}

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

int main()
{
	int n = 0;
	stack<int>s;
	bool flag = false; 

	while (scanf("%d" , &n) != EOF){

		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;
    cin>>n;
    s.push(n);
    while(cin>>n){
        if(n==0){
            cout<<s.top()<<endl;
            s.pop();
        }
        else{
            s.push(n);
        }
    }
}

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

using namespace std;

int main() {

	stack<int> st;
	int a, ans[100]={0},i = 0;

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

	
	return 0;
}

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

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

int main() {
	int n, count = 0, a[11], i;
	stack<int> s;
	while (cin >> n,n>=0,!cin.eof()) {
		if (n > 0) s.push(n);
		else if (n == 0) {
			a[count++] = s.top();
			s.pop();
		}
	}
	for (i = 0; i < count; i++) {
		cout << a[i] << endl;
	}
}

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

using namespace std;

void solve()
{
	stack<int> Stack;
	int Input;
	while(cin >> Input)
	{
		if(Input)
		{
			Stack.push(Input);
		}
		else
		{
			cout << Stack.top() << endl;
			Stack.pop();
		}
	}
}

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