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 <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[202][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[201] = {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 << "ouput"<< 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<stack>
#include<iostream>
using namespace std;

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

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

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

	while(cin >> input){
		if(input == 0){
			i--;
			cout << car[i] << endl;
		}else{
			car[i] = input;
			i++;
		}
	}
}

C++: #include <cstdio>
#include <stack>
using namespace std;
int main(){
	int n;
	stack<int> car;
	while(scanf("%d",&n)!) {
		if(n!=0) car.push(n);
		else{
			printf("%d\n",car.top());
			car.pop();
		}
	}	
	return 0;
}

C++: #include <stdio.h>

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

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

using namespace std;

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

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

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

using namespace std;

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

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

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num==0 && point>=0) pop();
		else push(num);
	}

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int i=0,num,a[10],b[10000],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<bits/stdc++.h>

using namespace std;

int str1[100],str2[100],mo;

int  s=1,t1,t2;

int main(){


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


    if(mo!=0){
        str1[t1]=mo;
        t1++;

    }else {
        str2[t2++]=str1[--t1];

    }

    if(t1==0)break;

    }

    for(int i=0;i<100;i++){

            if(str2[i]==0)break;
        cout << str2[i] << endl;
    }


return 0;
}

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

using namespace std;

int main(void) {

	/*
	double x[3] = { 0,0,0 };
	double y[3] = { 0,0,0 };
	double xp = 0, yp = 0;
	int flag[3] = { 0,0,0 };

	while (cin >> x[0]>> y[0]>> x[1]>> y[1]>> x[2]>> y[2]>> xp>> yp) {
		for (int i = 0; i < 3; i++) {
			int temp1 = (i + 1) % 3;
			int temp2 = (i + 2) % 3;
			double checkI = (y[temp1] - y[i]) * (x[temp2] - x[i]) - (x[temp1] - x[i]) * (y[temp2] - y[i]);
			double checkP = (y[temp1] - y[i]) * (xp - x[i]) - (x[temp1] - x[i]) * (yp - y[i]);

			if (checkI * checkP > 0) {
				flag[i] = 1;
			}
		}
		if (flag[0] == 1 && flag[1] == 1 && flag[2] == 1) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		flag[0] = 0;
		flag[1] = 0;
		flag[2] = 0;
	}
	*/
	int input_num;
	vector<int> train_num;
	while (cin >> input_num) {
		if (input_num == 0) {
			cout << train_num.back() << endl;
			train_num.pop_back();
		}
		else if (input_num >= 1 && input_num <= 10) {
			train_num.push_back(input_num);
		}
	}

	return 0;
}

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

stack<int> car;

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

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

using namespace std;

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

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

int main(){
	stack<int> s;
	int a;
	while	( scanf(" %d", &a) != EOF ){
		if(a==0) {
			cout << s.top() << endl;
			s.pop();
		}
		else s.push(a);
	}
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

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

int main(){
        using namespace std;

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

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>

using namespace std;

stack<int> s;

int main(void){
	while (true){
		int n;
		scanf("%d", &n);
		if (n != 0) s.push(n);
		else if (n == 0) {
			cout << s.top() << endl;
			s.pop();
		}
		if (s.empty()) break;
	}
}

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

template <typename TYPE>
class my_stack{
public:
	my_stack(){};
	void push(TYPE x){
		vec.push_back(x);
		return;
	};
	TYPE pop(){
		TYPE x = vec.back();
		vec.pop_back();
		return x;
	};

private:
	vector<TYPE> vec;
};

int main()
{
	my_stack<int> stack;
	int n;
	while (cin >> n){
		if (n) stack.push(n);
		else cout << stack.pop() << "\n";
	}
	cout << flush;
}

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();
		} else {
			st.push(a);
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <stack>
using namespace std;

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

C++: #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
  int car;
  stack<int> rail;
  while(cin >> car){
    if(car != 0){
      rail.push(car);
	}
    else{
      cout << rail.top();
      rail.pop();
    }
  }
}