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

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

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
main(){
	int t[101],co=0;
	for(int i=0;i<=100;++i)t[i]=0;
	while(1){
		cin>>t[co];
		if(t[co]==0){
			--co;
			cout<<t[co]<<endl;
		}else ++co;
		if(co==0)break;
	}
}

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

int main(void){
  int input;

  std::stack<int> st;

  while(std::cin >> input ){
    if(input != 0){
      st.push(input);
    }
    else{
      std::cout << st.top()<<std::endl;
      st.pop();
    }
  }

  return 0;
}

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

int main(){
	int in[10],out[10];
	int in_num=0;
	int out_num=0;
	int n;
	while(cin >>n){
		if(n == 0){
			in_num--;
			out[out_num] = in[in_num];
			cout << out[out_num]<<endl;
			out_num++;
		}
		else {
			in[in_num] = n;
			in_num++;
		}
	}
	return 0;
}

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

C++: #include <iostream>
#include <stack>
   
int main(){
    std::stack<u_int> train;
    u_int num;
    while(std::cin >> num){
        if(num == 0){
            std::cout << train.top() << std::endl;
            train.pop();
        }else{
            train.push(num);
        }
    }
    return 0;
}

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

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

using namespace std;

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

C++: #include <iostream>

using namespace std;

int main() {

	int i, j=0, n, a[10], b[10];

	for(i=0; i<10; i++) {
		b[i]=0;
	}

	i=0;
	while(1) {
		cin >> n;
		if(n==0) {
			b[j]=a[i-1];
			j++;
			i--;
			a[i]=n;
			if(i==0)
				break;
			continue;
		}
		a[i]=n;
		i++;
	}

	for(i=0; b[i]!=0; i++) {
		cout << b[i] << endl;
	}

	return 0;

}

C++: #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{
      cout << s.top()<<endl;
      s.pop();
    }
  }
  return 0;
}

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

using namespace std;

int main()
{
    stack<int> st;

    int a;

    cin >> a;
    st.push(a);

    while (cin >> a) {
        if (a) st.push(a);
        else { cout << st.top() << endl; st.pop(); }
    }
}

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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

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

C++: #include<iostream>
using namespace std;
int b[10000000];
int main(){
  int i=0,num,a[10],x=0;
  
  while(cin>>num){
    if(num==0){
      b[x++]=a[i-1];
      i--;
    }
    else  a[i++]=num;
    if(!i)break;
  }
  
  for(i=0;i<x;i++)
    cout<<b[i]<<endl;
  return 0;
}

C++: // 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
#ifdef DAIJOBU
#include "/home/v-o_o-v/deb.h"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif 

using namespace std;

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

	int n;
	vector<int> v;
	while(cin >> n){
		if(n == 0){
			cout << v.back() << '\n';
			v.pop_back();
		}else v.push_back(n);
	}
	return 0;
}
// Write Here

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

int main() {
	int n[50], x, i=0,flag=0,check=0;
	for (;;) {
		cin >> x;
		if (x == 0 && flag == 1) {
			i--;
			cout << n[i - 1];
			flag = 1;
			check = 1;
		}
		else if (x == 0) {
			cout << n[i - 1];
			flag = 1;
			check = 1;
		}
		else if (x > 0) {
			if (check == 1) {
				i--;
				check = 0;
			}
			n[i] = x;
			i++;
			flag = 0;
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
#include <stack>

using namespace std;
double T_area(double x1,double y1, double x2, double y2, double x3, double y3);

int main(){
    stack<int> st;    // int型のスタック
    int n;
    while(scanf("%d",&n)!=EOF){
        if(n!=0){
            st.push(n);
        }else{
            cout << st.top() << "\n";
            st.pop();
        }
    }
    
    
}

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

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

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

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

int main()
{
    list<int> stack;

    for (int n; cin >> n;)
        if (n == 0) {
            cout << stack.front() << endl;
            stack.pop_front();
        } else
            stack.push_front(n);

    return 0;
}

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

int main(){
  stack<int> st;
  int n,a;

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

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

int main() {
	std::stack<int> stCar;
	std::queue<int> qOut;
	int number;

	while (std::cin >> number) {
		if (number != 0) {
			stCar.push(number);
		} else {
			qOut.push(stCar.top());
			stCar.pop();
		}
	}

	while (!qOut.empty()) {
		std::cout << qOut.front() << '\n';
		qOut.pop();
	}
	return 0;
}