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(){
  int n;
  vector<int> Stop, Free;

  while(cin >> n){
    if(n == 0){
      n = Stop[Stop.size()-1];
      Stop.pop_back();
      Free.push_back(n);
    }else{
      Stop.push_back(n);
    }
  }

  for(vector<int>::size_type i=0; i != Free.size(); ++i){
    cout << Free[i] << endl;
  }

  return 0;
}

C++: #include<stdio.h>
int main(void)
{
    int train[10]={0},n,count=0,outTrain[10],trainCount=0;
    while(scanf("%d",&n)!=EOF){
        if(n){
            for(int i=count ; i!=0 ; i--){
                train[i]=train[i-1];
            }
            train[0]=n;
            count++;
        }
        else{
            outTrain[trainCount]=train[0];
            for(int i=0 ; i<count ; i++){
                train[i]=train[i+1];
            }
            train[count]=0;
            count--;
            trainCount++;
        }
    }
    for(int i=0 ; i<trainCount ; i++){
        printf("%d\n",outTrain[i]);
    }
    return 0;
}

C++: #include <stdio.h>

int train(int array[], int a)
{
	int i;
	for(i=0; i<10; i++)
	{
		if(array[i]==0)
		{
			if(a)
			{
				array[i]=a;
				return 0;
			}
			
			if(i>0 && a==0)
			{
				printf("%d\n", array[i-1]);
				array[i-1]=0;
				return 0;
			}
		}
	}
}
	

int main (void)
{
	int a, trains[10], i;
	
	for(i=0; i<10; i++)
	{
		trains[i]=0;
	}
	
	while(scanf("%d", &a)!=EOF)
	{
		train(trains, a);
	}
	
	return 0;
}

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

int main()
{
	vector<int> S;

	int c;
	while(cin>>c)
	{
		if(c==0)
			cout<<S.back()<<endl,
			S.pop_back();
		else
			S.push_back(c);
	}
	return 0;
}

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

int main(){
	int a[100], i = 0;
	while (true){
		cin >> a[i];
		if (cin.eof()) { break; }
		if (a[i] == 0 ){
			cout << a[i - 1] << endl;
			i--;
		}
		else { i++; }
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int car;
	int a[11];
	int i,s;
	i=0;
	while(scanf("%d",&car)!=EOF){
		if(car!=0){
			a[i]=car;
			i++;
		}
		else {
			i--;
			printf("%d\n",a[i]);
		}
	}
	return 0;
}

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

int main() {
	int in;
	vector <int> a;
	while (cin >> in) {
		if (in == 0) {
			cout << a.back();
			a.pop_back();
			/*if (a.size() == 0)
				break;
			else*/
				cout << endl;
		}
		else
			a.push_back(in);
	}
	return 0;
}

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

stack<int> sta;

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

}

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

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

using namespace std;

int main() {
    stack<int> st;

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



    return 0;
}

C++: #include<stack>
#include<deque>
#include<iostream>
using namespace std;
int main(){
	int m,n;
	deque<int>deq;
 	while(1){
	    cin>>n;
	    if(n!=0) deq.push_back(n);
	    else {  
                     if(deq.empty()) { continue;}
                     else {     cout<<deq[(int)deq.size()-1]<<endl;
				deq.pop_back();}
            }
	}
        return 0;
}

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

int main() {
	
	int n , m[12] = {} ;
	
	while( cin >> n ){
		if( cin.eof() ) break ;
		if( n==0 ){
			for( int i=11 ; i>=0 ; i-- ){
				if( m[i] != 0 ){
					cout << m[i] << endl ;
					m[i] = 0 ;
					break ;
				}
			}
		}
		else {
			for( int i=0 ; i<12 ; i++ ){
				if( m[i] == 0 ){
					m[i] = n ;
					break ;
				}
			}
		}
	}
	
	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;
}