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 <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int main(){
    stack<int> s;
    int n, ans[100], ct = 0;
    while (cin>>n){
        if (n == 0) {
            ans[ct] = s.top();
            //cout << s.top() << endl;
            s.pop();
            ct++;
        } else {
            s.push(n);
        }
    }
    REP(i, ct){
        cout << ans[i] << endl;
    }
}

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

using namespace std;

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

C++: #include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	stack<int> st;
	queue<int> ans;

	int v;
	while (cin >> v) {
		if (v == 0) {
			ans.push(st.top());
			st.pop();
		} else {
			st.push(v);
		}
	}

	if (ans.empty()) {
		cout << 0 << endl;
	} else {
		while (!ans.empty()) {
			cout << ans.front() << endl;
			ans.pop();
		}
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
using namespace std;

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

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B)          for(int I=A; I<B; I++)
#define LL                  long long
#define PII                 pair<int,int>
#define MOD                 1000000007
#define MAX                 1000005
#define READ(A)             freopen(A,"r",stdin)

int main() {
    //READ("input.txt");
    stack<int>S;
    int N;

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

C++: #include<stdio.h>
const int SIZE=100;
int data[SIZE];
int sp=0;
int size(){
  return sp;
}
int empty(){
  return sp<=0;
}
int isfull(){
  return sp>=SIZE;
}
int top(){
  return data[sp-1];
}
void pop(){
  sp--;
}
void push(int v){
  data[sp]=v;
  sp++;
}
int main(){
  int k,n;
  for(k=0;k<100;k++){
    scanf("%d",&n);
    if(!empty(){
      if(n==0){
        printf("%d\n",top());
        pop();
      }
    }else{
      if(!isfull()){
        push(n);
      }
    }
  }
  return 0;
}

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

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

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

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

int main()
{
        int train;
        stack<int> out;
        while(cin >> train)
        {
                if(train != 0){
                        out.push(train);
                }
                else{
                        cout << out.top() << " ";
                        out.pop();
                }
        }
        return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
	int num, tmp[10] = {0}, num_out[100] = {0};
	int cnt_1 = 9, cnt_2 = 0;
	
	while (scanf("%d", &num) != EOF){
		if (num == 0){
			num_out[cnt_2] = tmp[cnt_1 + 1];
			printf("num_out[%d]=%d\n", cnt_2, num_out[cnt_2]);
			cnt_2++;
			cnt_1++;
		}
		else {
			tmp[cnt_1] = num;
			printf("tmp[%d]=%d\n", cnt_1, tmp[cnt_1]);
			cnt_1--;
		}
	}
	
	for (int i = 0; i < 100; i++){
		if (num_out[i] != 0){
			printf("%d\n", num_out[i]);
		}
	}
	
	return (0);
}

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

int main() {
	int temp; vector<int> vec(0);
	while (cin >> temp) {
		if (temp == 0) {
			cout << vec[vec.size() - 1] << endl;
			vec.pop_back();
		}
		else vec.push_back(temp);
	}
	return 0;
}

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

stack <int> st;

void enter(int car) {
  st.push(car);
}

void exit() {
  cout << st.top() << endl;
  st.pop();
}

int main() {
  int car;
  while (cin >> car) {
    if (car == 0) {
      exit();
    } else {
      enter(car);
    }
  }
}

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

int main();


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

	while (std::cin >> dummy){
		if (dummy == 0){
			input.pop();
		}
		else{
			input.push(dummy);
		}
	}

	while (!input.empty()){
		std::cout << input.top() << std::endl;
		input.pop();
	}

	//while (1);
	return 0;
}

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

using namespace std;

int main(){
    stack<int> in;
    for(int n; cin >> n; )
        if(n != 0) in.push(n);
        else cout << in.top() << endl, in.pop();

    return 0;
}

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

int main() {
	int rail[10]={0};
	int n,i=0;
	while(cin>>n){
		if(n==0){
			cout<<rail[i-1]<<endl;
			i--;
			continue;
		}
		rail[i]=n;
		i++;
	}
	return 0;
}

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

using namespace std;

int main()
{
	stack<int> st;
	int in;

	while (~scanf("%d", &in)){
		if (in) st.push(in);
		else {
			printf("%d\n", st.top());
			st.pop();
		}
	}

	return (0);
}

C++: #include<iostream>
using namespace std;
int main(){
int a[]={0,0,0,0,0,0,0,0,0,0};
int b;
while(cin>>b){
if(b==0){
cout<<a[0];
for(int i=0;i<9;i++){
a[i]=a[i+1];}}
else{
for(int i=0;i<8;i++){
a[9-i]=a[8-i]}
a[0]=b;}}

C++: #include<stdio.h>
int main(){
int a[100];
int j;
for(int i=0;;i++){
scanf("%d",&a[i]);
if(a[i]==0){
j=i;
while(){
if(j1!=0){
printf("%d",a[j1]);
break;
}
j--;
}
}
}

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

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num == 0 && point > 0) pop();
		else push(num);
	}

    return 0;
}