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

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

C++: #include<iostream>
#include<stack>
#include<vector>
int main(){
	std::stack<int> st;
	std::vector<int> vec;
	int a=0;
	while(1){
		int n;
		std::cin>>n;
		if(std::cin.eof())break;
		if(n!=0)st.push(n);
		else vec.push_back(st.top()),a++,st.pop();
	}
	for(int i=0;i<a;i++)std::cout<<vec[i]<<std::endl;
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>

#define int64 long long int

using namespace std;

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

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

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

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

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

int main(){
  std::stack<int>s;
  for(int x;~scanf("%d",&x);)
    if(x)s.push(x);
    else printf("%d\n",s.top()),s.pop();
}

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

int main(){
	int x;
	stack<int> S;
	while(1){
		cin>>x;
		if(x==0){
			printf("%d\n",S.top());
			S.pop();
		}else{
			S.push(x);
		}
	}
	return 0;
}

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

using namespace std;

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

  return 0;
}

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

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

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void)
{
    int a[250][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[220] = {0};
    bool judge = true;
    int tempjudge = 0;
    
    while(judge)
    {
        cin >> a[i][0];
        if(a[i][0] == 0)
        {
            a[i][1] = 1;
            RFOR(j,i,-1)
                if(a[j][1] != 1 )
                {
                    answer[l] = a[j][0];
                    a[j][1] = 1;
                    cout << answer[l] << endl;
                    l++;
                    break;
                }
        }
        REP(k,i+1)
        if(a[k][1] != 1){
                judge = true;
                break;
        }
        else
            judge = false;
                
        
        i++;
    }

    return 0;
}

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

using namespace std;

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

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

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<stack>
using namespace std;
int main(){
    int tra,ans[20];
    stack<int> s;
    for(int i=0;i<20;i++){
        cin>>tra;
        if(tra==0){
            cout<<s.top()<<endl;
            s.pop();
        }else{
            s.push(tra);
        }
    }
}

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

using namespace std;
int num;
stack<int> s;

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

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

#define MAX 256

int main(void){
	
	int i=0,j=0,x;
	int a[MAX];
	int ans[MAX];
	while(cin>>x){
		if(x==0){
			ans[j]=a[i-1];
			j++;
			i--;
		}else{
			ans[i]=x;
			i++;
		}
		
		
	}
	
	for(int i=0;i<j;i++){
		cout<<ans[i]<<endl;
	}
	
}

C++: #include<iostream>

using namespace std;

int main() {
	int train[200000] = { 0 }, junban[200000] = { 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 <iostream>

using namespace std;

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

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


int main()
{
	int car[10] = {}, b[100];
	int i = 0, cou = 0;
	while (cin >> b[i]) {
		if (b[i] != 0) {
			car[cou] = b[i];
			cou++;
		}
		if (b[i] == 0) {
			cout << car[cou - 1] << endl;
			cou--;
		}
		i++;
	}
    return 0;
}

C++: #include <stdio.h>

int main(void){
	int stack[10];
	int sp = -1;
	int n = 0;
	for(int i=0;i<10;++i){
		stack[i] = 0;
	}
	while(scanf("%d", &n) != EOF){
		if(n == 0){
			printf("%d\n", stack[sp]);
			sp--;
		}else{
			stack[++sp] = n;
		}
	}
	return 0;
}

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

int main()
{
	stack<int> R;
	int n;
	int car[10];
	int i = 0;
	
	while (cin >> n){
		if (n == 0){
			car[i] = R.top();
			R.pop();
			i++;
		}
		else {
			R.push(n);
		}
	}
	
	for (int j = 0; j < i; j++){
		cout << car[j] << endl;
	}
	
	return (0);
}

C++: import java.util.ArrayDeque;
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	ArrayDeque<Integer> stack = new ArrayDeque<Integer>();
	int n;
	while (scan.hasNext()) {
	    n = Integer.parseInt(scan.nextLine());
	    if (n == 0) {
		System.out.println(stack.pop());
	    } else {
		stack.push(n);
	    }
	}
    }
}

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

	int main(void){
		int train[100];
		int count = 0;
		int n;
		while(cin >> n){
			if(n > 0){
				train[count] = n;
				count++;
			}else if(n == 0){
				count--;
				cout << train[count] << endl;
			}
		}
		return 0;

	}

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

using namespace std;

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

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

using namespace std;
long long int num;
stack<int> s;

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

C++: #include <stack>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	stack<int> a;
	vector<int> o;
	int s=1,d;
	
	cin>>d;
	a.push(d);
	
	while(s!=0){
		cin>>d;
		if(d!=0) {
			a.push(d);
			s++;
		}
			else {
				s--;
				o.push_back(a.top());
				a.pop();
			}
	}
	for(int i=0;i<o.size();i++) {
		cout<<o[i]<<endl;
	}
}