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

using namespace std;

int main()
{
    vector<int> Car;
    int Size = 0;
    int number;
    vector<int> Order;

    while(cin >> number)
    {

            if(number != 0)
            {
                Car.push_back(number);
            }
            else if(number == 0)
            {

                Order.push_back(Car[(Car.size())-1]);
                Car.pop_back();

            }




    }
            for(int z = 0; z < Order.size(); z++)
        {
            cout << Order[z] << endl;
        }
}

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

using namespace std;

int main() {
  int n;
  vector<int> train;

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

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

using namespace std;

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

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>
#include <stack>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int in;
  stack<int> s;

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

  return 0;
}

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

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

using namespace std;

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

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

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

using namespace std;

int main(){
	vector<int> RailRoad, out;
	int buf;

	// 入力の終わりまで読み込み
	while(cin >> buf){
		if(buf == 0){
			buf = RailRoad[((int)RailRoad.size() - 1)];
			out.push_back(buf);
			RailRoad.pop_back();
		}else{
			RailRoad.push_back(buf);
		}
	}

	// イテレータの初期化
	for(vector<int>::iterator it = out.begin();it != out.end();++it){
		cout << *it << endl;
	}

	return 0;
}

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

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

C++: #include <stdio.h>
#include <string.h>

int st[10];

int main()
{
	int stn = 0;
	while(1)
	{
		int n;
		if(EOF == scanf("%d",&n))
		{
			break;
		}
		if(n == 0)
		{
			stn--;
			printf("%d\n",st[stn]);
		}
		else
		{
			st[stn] = n;
			stn++;
		}
	}
	return 0;
}

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

int main(){
	int out[10], car[10];
	int x, k = 0, i = 0;
	while(cin >> x){
		if(x != 0){
			car[i] = x;
		}
		else{
			out[k] = car[i-1];
			i = i-2;
			k++;
		}
		i++;
	}
	for(int j = 0; j < k; j++){
		cout << out[j] << endl;
	}
}

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

using namespace std;

int main() {
  stack<int> cars;
  do {
    int car;
    cin >> car;
    if (car == 0) {
      cout << cars.top() << endl;
      cars.pop();
    } else {
      cars.push(car);
    }
  } while (!cars.empty());

  return 0;
}

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

using namespace std;

int main(){
  vector<int> train;
  vector<int> queue;
  int num;

  while(cin >> num){
    if(num != 0){
      train.push_back(num);
    }else{
      queue.push_back(train.back());
      train.pop_back();
    }
  }

  for(int i=0; i<queue.size(); i++){
    cout << queue[i] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>

using namespace std;

int main(){
	int n;
	vector<int> ans;
	stack<int> a;
	while (cin >> n) {
		if (n > 0)a.push(n);
		else if (n == 0) {
			int temp;
			temp = a.top();
			ans.push_back(temp);
			a.pop();
		}
	}
	for (int i = 0; i < ans.size(); i++)cout << ans[i] << endl;
	return 0;
}

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

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

int main(){
	int out[100], car[100];
	int x, k = 0, i = 0;
	while(cin >> x){
		if(x != 0){
			car[i] = x;
		}
		else{
			out[k] = car[i-1];
			i = i-2;
			k++;
		}
		i++;
	}
	for(int j = 0; j < k; j++){
		cout << out[j] << endl;
	}
}

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

int main()
{
	int train[100000]={};
	long int i=0;
	for(int j=0;j<20;j++){
		cin>>train[i];
		if(train[i]==0){
			i--;
			cout<<train[i]<<endl;
		}else{
			i++;
		}
	}
}

C++: #include "bits/stdc++.h"
#include <cstdio>
#include <cmath>
using namespace std;

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

C++: #include <stdio.h>

int main() {
	int a,i,k,m;
	int data[100] = {0};
	int output[100] = {0};
	while(scanf("%d", &a) != EOF) {
		if (a != 0) {
			for (k = 0; k < 100; k++) {
				if (data[k] == 0) {
					data[k] = a;
					break;
				}
			}
		}
		else {
			for (k = 0; k < 100; k++) {
				if (data[k] == 0) {
					for (m = 0; m < 100; m++) {
						if (output[m] == 0) {
							output[m] = data[k - 1];
							break;
						}
					}
					data[k - 1] = 0;
					break;
				}
			}
		}
	}
	for (i = 0; i < 100; i++) {
		if (output[i] != 0) {
			printf("%d\n", output[i]);
		}
	}
	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);
	
	int a;
	while(cin >> a){
		if(a == 0){
			cout << s.top() << endl;
			s.pop();
		}
		else {
			s.push(a);
		}
	}
	
	return 0;
}