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 <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    vector<int> ans;
    stack<int> stk;
    int v;
    while(cin>>v){
        if(v==0){
            ans.pb(stk.top());
            stk.pop();
        }else{
            stk.push(v);
        }
    }
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
    return 0;
}

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

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

C++: #include<stdio.h>
#include<iostream>
#include<stack>
#include<cstdio>
using namespace std;
int main(){
	stack<int> s;
	int n;
	while((scanf("%d",&n))!=EOF){
		if(n!=0){
			s.push(n);
		}else{
			printf("%d\n",s.top());
			s.pop();
		}
	}
	return 0;
}

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

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

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

using namespace std;

int main()
{
	int train;
	stack<int> rail;

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

	return 0;
}

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

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

C++: #include<iostream>
int main(){for(int n,t[10],*p=t;!(std::cin>>n).eof();)n?*p++=n:printf("%d\n",*--p);}

C++: #include<iostream>
#include<stack>
#include<vector>
using namespace std;
#define ARRAY_MAX 110

int main(void){

  int i = 0;
  int n;
  stack<int> Stack;
  vector<int>array(ARRAY_MAX,0);

  while(cin >> n){
    if(n){
      Stack.push(n);
    }else{
      cout << Stack.top() << endl;
      Stack.pop();
    }
  }
  return 0;
}

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


int main(){

  int train[10] , num[10];

 for( int i = 0; i < 10; i++ ){
    train[i] = 0;
    num[i] = 0;
 }

  for( int i = 0; i < 10; i++ ){

    cin >> train[i];

    if( train[i] == 0 ){
      for( int j = i; j >= 0; j-- ){
	if( train[j] != 0 ){
	num[i] = train[j];
	train[j] = 0;
	break;
	}
      }
    }
  }
  

  for( int k = 0; k < 10; k++ ){
    if( num[k] != 0 ) cout << num[k] << endl; 

  }


  return 0;
}

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

//????°?????????\???????????§back?????????????????????
int main() {
    int n;
    list<int> l={0};
    while (scanf("%d",&n)!=EOF) {
        if (n==0) {
            printf("%d\n",l.front());
            l.pop_front();
        } else {
            l.push_front(n);
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <math.h>
#include <string>
#include <cmath>
#include <iomanip>

int main();


int main(){
	std::stack<int> input;		//入力される数（車両番号）を格納する
	std::vector<int> output;	//出力される車両番号
	int dummy = 0;				//ダミーナンバー
	int count = 0;

	//while (count < 8){
		//std::cin >> dummy;
		//count++;
	while (std::cin >> dummy){
		if ((dummy == 0) && (!input.empty())){
			output.push_back(input.top());
			input.pop();
		}
		else if((1 <= dummy) && (dummy <= 10)){
			input.push(dummy);
		}
		else{
			//何もしない
		}
	}

	for (int i = 0; i < output.size(); i++){
		std::cout << output[i] << std::endl;
	}

	//while (1);
	return 0;
}

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

int a[11];
int b, t;

int main() {
  cin>>a[0];
  t=1;
  
  while(t>1) {
    cin>>b;
    if(b>0) {
      a[t]=b;
      t++;
    }else {
      cout<<a[t-1]<<endl;
      t--;
    }
  }
  
  return 0;
}

C++: #include <iostream>
#include <stack>
#include <cstdio>
using namespace std;
int main(){
  stack<int>st;
  int a;
  cin >> a;
  st.push(a);
  while(scanf("%d",&a) != EOF){
    if(!a){
      cout << st.top() << endl;
      st.pop();
    }else{
      st.push(a);
    }
  }
  return(0);
}

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

using namespace std;

int main(){
    int c, num;
    stack <int> s;
    while(1){
        cin >> num;
        if(!num){
            if(!c) break;
            else{
                cout << s.top() <<endl;
                s.pop();
            }
        }
        else{
            if(c==10) cout << "Already Full" <<endl;
            else s.push(num);
        }
    }
    return 0;
}

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

int main() {
	int g;
	stack<int> a;
	queue<int> b;
	while(cin >> g) if (g!=0) a.push(g); else { b.push(a.top()); a.pop();}
	while(!b.empty()) { cout << b.front() << endl; b.pop(); } 
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	stack<int> s;
	int n;
	while(scanf("%d",&n)!=EOF){
		if(n==0){
			cout<<s.top()<<endl;
			s.pop();
		}
		else{
			s.push(n);
		}
	}
	return 0;
}

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

using namespace std;

int main() {
	int n;
	stack<int> s;
	while (true) {
		cin >> n;

		if (n == 0) {
			cout << s.top() << endl;
			s.pop();
		}
		else {
			s.push(n);
		}
	}
	return 0;
}