Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Railway struct {
	trains trains
}

type trains []int

func main() {
	var stdin string
	var s = bufio.NewScanner(os.Stdin)

	railway := Railway{}
	for s.Scan() {
		stdin = s.Text()

		n, err := strconv.Atoi(stdin)
		if err != nil {
			continue
		}
		railway.lifo(n)
	}
}

func (r *Railway) lifo(n int) {
	if n == 0 {
		if len(r.trains) == 0 {
			return
		}
		fmt.Println(r.trains[len(r.trains)-1])
		r.trains = r.trains[:len(r.trains)-1]
	} else {
		r.trains = append(r.trains, n)
	}
}

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();
    }
  }
}

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

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

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

int main()
{
    int n;
    int stack[10];
    int index=0;
    vector<int> r;
    while (scanf("%d",&n) != EOF)
    {
	if (n!=0)
	{
	    stack[index] = n;
	    index++;
	} else {
	    r.push_back(stack[index-1]);
	    index--;
	}
    }
    for (int i=0; i<r.size(); i++)
    {
	cout << r[i] << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int main(){
	int car[10]={0,0,0,0,0,0,0,0,0,0};
	int a,c=0;
	
	while(~scanf("%d",&a)){
		if(a==0){
			c--;
			printf("%d",car[c]);
		}
		else {
			car[c]=a;
			c++;
		}
	}
	return 0;
}