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<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    stack<string> st;
    while(cin >> s){
        if(s == "0"){
            cout << st.top() << endl;
            st.pop();
        }else{
            st.push(s);
        }
    }

    return 0;
}

C++: #include<stdio.h>
int main(){
  int sp=0,data[100],n,i;
  while(1){
    scanf("%d",&n);
    if(n==0){
      sp--;
      printf("%d\n",data[sp]);
    }else{
      data[sp]=n;
      sp++;
    }
  }
}

C++: #include <stdio.h>

int main() {
	int a,i,k,m;
	int data[15] = {0};
	int output[15] = {0};
	for (i = 0; i < 15; i++) {
		scanf("%d", &a);
		if (a != 0) {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					data[k] = a;
					break;
				}
			}
		}
		else {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					for (m = 0; m < 15; m++) {
						if (output[m] == 0) {
							output[m] = data[k - 1];
							break;
						}
					}
					data[k - 1] = 0;
					break;
				}
			}
		}
	}
	for (i = 0; i < 15; i++) {
		if (output[i] != 0) {
			printf("%d\n", output[i]);
		}
	}
	return 0;
}

C++: #include<cstdio>
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>
#include <stack>

int main(){
	std::stack<int> st;

	int n;

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

	return 0;
}

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

int main(){
	int ans[11],tmp,i = 0,j,k = 0,f[11];

	while(cin>>tmp){
		if(tmp == 0){
			ans[k] = f[i-1];
			f[i-1] = '\0';
			i--;
			k++;
		}
		else{
		f[i] = tmp;
		i++;
		}
	}
	for(j = 0;j < k;j++){
		cout<<ans[j]<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(){
	int i=0, j=0, num;
	int a[20], b[20];
	for(int i=0 ; i<20 ; i++){
		a[i] = 0;b[i]=0;
	}
	
	while( scanf("%d", &num) != EOF ){
		if(num==0){
			b[j] = a[i-1];
			j++;
			i--;
		}else{
			a[i] = num;
			i++;
		}
		if(i==0) break;
	}
	for(int n=0; n<j ; n++){
		printf("%d\n", b[n]);
	}
	
	return 0;
}

C++: /*Filename: aoj0013.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <stack>

using namespace std;

int main(){
	int num = 0;
	stack<int> car;

    while(cin >> num){
        if(num == 0){
        	cout << car.top() << endl;
        	car.pop();
        }
        else{
        	car.push(num);
        }
    }

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for (int i=n;^i;i--)
#define ALL(v) v.begin(),v.end()
// #define int ll 
#define eps 1e-9
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
typedef long long ll;

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

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(){
  int train[10];
  int by[10];
  int a,i=0,j=0;
  while(scanf("%d",&a)!=EOF){
    if(a==0){
      i--;
      by[j]=train[i];
      j++;
    }
    else{
      train[i]=a;
      i++;
  }
  }
  for(int i=0;i<j;i++){
    cout<<by[i]<<endl;
  }
}

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

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

C++: #include <stdio.h>

#include <string.h>

#include <stack>

#include <iostream>


using namespace std;

int main(){
    
    int input;
    stack<int> train;
    while (scanf("%d",&input)!=EOF) {
//        scanf("%d",&input);
        if (input!=0)train.push(input);
        else {
            printf("%d\n",train.top());
            train.pop();
        }
    }
}
    //        if(strcmp(c,pu) == 0){
    //
    //            scanf("%s",&color);
    //
    //            st.push(color);
    //
    //        }
    //
    //        if(strcmp(c,po) == 0){
    //
    //            cout<<st.top()<<endl;
    //
    //            st.pop();
    //
    //        }
    //
    //        if(strcmp(c,qu) == 0){
    //
    //            return 0;
    //
    //        }
    //
    //    }
    
    //}

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

int main() {
	int s[10];
	int ss = 0;
	while(true) {
		int x;
		if(scanf("%d", &x)<1)break;
		if(x==0) {
			printf("%d\n",s[--ss]);
		} else {
			s[ss++]=x;
		}
	}
	return 0;
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
 
 int main()
 {
   int N;
   stack<int> mystack;
   while(cin>>N)
   {
     if(N!=0) mystack.push(N);
     else
     {
       int m=mystack.top();
       mystack.pop();
       cout<<m<<endl;    
     }               
   }
   //while(1);      
   return 0;    
 }