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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    
    int tmp;
    stack<int> s;
    queue<int> q;
    
    while(cin >> tmp) {
        if(tmp == 0) {
            q.push(s.top());
            s.pop();
        } else {
            s.push(tmp);
        }
    }
    
    while(!q.empty()) {
        cout << q.front() << endl;
        q.pop();
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>

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

C++: #include<stdio.h>

int	i	=	0,	result;
int	train[100];
int outtrain[100];

void	push(int	k){
	train[i]	=	k;
	i++;
}

void	pop(int train[]){
	int	a,	check	=	0;
	for(a	=	i	-	1;	a	>=	0;	a--){
		if(train[a]	!=	0){
			result	=	train[a];
			train[a]	=	0;
			check	+=	1;
		}
		if(check	!=	0)break;
	}
}


int	main(){
	int	k,	cnt	=	0;
	outtrain[100]	=	0;
	while(1){
		scanf("%d",	&k);
		push(k);
		if(k	==	0){
			pop(train);
			outtrain[cnt]	=	result;
			cnt++;
			i	-=	2;
		}
		if(i	==	0)break;
	}
	for(k	=	0;	k	<=	cnt;	k++){
		if(outtrain[k]	!=	0)printf("%d\n",	outtrain[k]);
	}
}

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


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

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

using namespace std;

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

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

int main(){
	std::vector<int> line;
	std::vector<int> out;
	int a;

	while(std::cin >> a){
		if(a != 0){
			line.push_back(a);
		}else if(a == 0){
			out.push_back(line.back());
			line.pop_back();
		}
	}

	for(int i=0; i<(int)out.size(); ++i){
		std::cout << out.at(i) << std::endl;
	}
}

C++: #include <iostream>
#include <deque>
using namespace std;
 
int main(int argc, char** argv) {
    deque<int> deq;
    int n;
    while(cin >> n) {
        if(n == 0) {
            cout << deq.back() << endl;
            deq.pop_back();
        }else {
            deq.push_back(n);
        }
    }
    return 0;
}

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

int main() {
	int n, count = 0, a[10], 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<stdio.h>
#include<stack>

int main(){
	int data[100]={0},i=0;
	std::stack<int> train;
	while(data[i] != EOF){
		scanf("%d",&data[i]);
		i++;
	}
	i=0;
	train.push(data[i]);
	i=1;
	while(data[i] != EOF){
		if(! train.empty()){
			if(data[i]==0){
				printf("%d\n",train.top());
				train.pop();
			}else{
				train.push(data[i]);
			}
		i++;
		}
	}
	return 0;
}

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

int main() {
  int tracks[10];
  int n;
  int p;

  p = 0;
  while (cin >> n) {
    if (n) {
      tracks[p++] = n;
    } else {
      cout << tracks[--p] << endl;
    }
  }

  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int main()
{
	vector<int> v;
	int n;
	while (cin >> n)
	{
		if (n != 0) v.push_back(n);
		else
		{
			cout << v.back() << endl;
			v.pop_back();
		}
	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second.first
#define T4 second.second.second

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1.0e-9

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

int main(void){
	int n;
	vector<int> car;

	cin >> n;
	car.push_back(n);

	while(!car.empty()){
		cin >> n;
		if(n!=0) car.push_back(n);
		else{
			cout << car.back() << endl;
			car.pop_back();
		}
	}
	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 <cstdio>
#include <cstring>
#include <stack>

using namespace std;

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

C++: #include<iostream>
using namespace std;
int main(){
  int s[10];
  int n;
  int now=0;
  while(cin>>n){
    if(n==0){
      cout<<s[now-1]<<endl;
      now--;
      if(now==0){return 0;}
    }
    else{
      s[now]=n;
      now++;
    }
  }
}

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

int main() {
  int i;
  int cnt = 0;
  std::vector<int> vec;
  while(cnt != 45) {
    scanf("%d", &i);
    if(i == 0){
      printf("%d\n", vec.back());
      vec.pop_back();
    }else{
      vec.push_back(i);
    }
    cnt++;
  }
  return 0;
}

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

int main()
{
  stack<int> trains;
  int i;
  do
  {
    cin >> i;
    if (i != 0) trains.push(i);
    else
    {
      if (trains.empty()) break;
      cout << trains.top() << endl;
      trains.pop();
    }
  } while (true);
  return 0;
}