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

using namespace std;

int main() {
    stack<int> q;
    while (true) {
        int n;
        if (scanf("%d", &n) == EOF)
            break;

        if (n) {
            q.push(n);
        } else {
            printf("%d\n", q.top());
            q.pop();
        }
    }

    return 0;
}

C++: #include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp= 0;

int size(){
 return sp;
}

int top(){ return data[sp-1];
}
void pop(){
 sp--;
}

void push(int v){
 data[sp] = v;
 sp++;
}

int main(){
 int v;
 while(scanf("%d", &v) != EOF){
  if(v != 0){
    push(v);
  }
  if(v == 0){
   printf("%d\n", top());
   pop();
  }
 }
 return 0;
}

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

int main()
{
	stack<int> s;
	deque<int> ans;
	int n;

	while (1)
	{
		cin >> n;
		if (n == 0)
		{
			ans.push_front(s.top());
			s.pop();
			if (s.empty()) break;
		}
		else
		{
			s.push(n);
		}
	}

	while (1)
	{
		if (!ans.empty())
		{
			cout << ans.back() << endl;
			ans.pop_back();
		}
		else break;
	}
	return 0;
}

C++: /*
 * Problem     : AOJ0013
 * Title       : Switching Railroad Cars
 * Author      : mizo0203
 * Copyright   : Your copyright free
 * Description : スタック
 */

#include <stdio.h>
#include <stack>
using namespace std;

int cn; // car number or 0
stack<int> st;

bool input() {

  if (scanf("%d", &cn) == EOF)
    return false;

  return true;
}

int main() {

  while (input()) {
    if (cn) st.push(cn);
    else {
      printf("%d\n", st.top());
      st.pop();
    }
  }

  return 0;
}

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

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

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

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

using namespace std;

stack<int>s;

int main(){
    
    do{
        int n;
        cin>>n;
        if(n!=0){
            s.push(n);
        }else{
            cout<<s.top()<<endl;
            s.pop();
        }
    }while(s.size()!=0);
    
    return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

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

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

int main()
{
        queue<int> op;
        queue<int> carrec;
        stack<int> car;
        int ops;
        int reccar;

        while(cin >> ops){
                op.push(ops);
        }

        while(!op.empty()){
                ops = op.front(); op.pop();
                if(ops != 0){
                        car.push(ops);
                }else if(ops == 0){
                        reccar = car.top();
                        carrec.push(reccar);
                        car.pop();
                }
        }

        while(!carrec.empty()){
                cout << carrec.front() << endl;
                carrec.pop();
        }

        return 0;
}

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

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

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

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

  return 0;
}

C++: #include<stdio.h>

int	i	=	0,	result;
int	train[100];
int outtrain[100];

void	push(int	k){
	train[i]	=	k;
	i++;
}

void	pop(int train[]){
	int	a,	check	=	0;
	for(a	=	i	-	1;	a	>=	0;	a--){
		if(train[a]	!=	0){
			result	=	train[a];
			train[a]	=	0;
			check	+=	1;
		}
		if(check	!=	0)break;
	}
}


int	main(){
	int	k,	cnt	=	0;
	outtrain[100]	=	0;
	while(scanf("%d",	&k) != EOF){
		push(k);
		if(k	==	0){
			pop(train);
			outtrain[cnt]	=	result;
			cnt++;
			i	-=	2;
		}
	}
	for(k	=	0;	k	<=	cnt;	k++){
		if(outtrain[k]	!=	0)printf("%d\n",	outtrain[k]);
	}
	return 0;
}

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


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

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

	return 0;
}

C++: #include <stdio.h>

#define N 20
int main(void){
    int stk[N], sp=0;
    int n;
   
    for (int i=0; i<N; i++) stk[i]=0;
    while (scanf("%d", &n)){
        if (n==0 && sp!=0){
            printf("%d\n", stk[--sp]);
        } else {
            stk[sp++] = n;
        }
    }
    return 0;
}

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

using namespace std;

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

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

int main()
{
	stack<int> R;
	int n;
	int car[1000];
	int i = 0;
	
	while (cin >> n){
		if (n == 0){
			car[i] = R.top();
			R.pop();
			i++;
		}
		else {
			R.push(n);
		}
	}
	
	for (int j = 0; j < i; j++){
		cout << car[j] << endl;
	}
	
	return (0);
}

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

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

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

int main(){
	vector<int> train;
	int n;
	while(cin >> n){
		if(n!=0){
			train.push_back(n);
		}
		else{
			cout << train.back() << endl;;
			train.pop_back();
		}
	}
	return 0;
}

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

struct stack{
	int element;
	struct stack *next;
};
int top(struct stack *s){
	return s->element;
}
struct stack* pop(struct stack *s){
	struct stack *p, *q;
	q = s;
	p = s->next;
	free(q);
	s = p;
	return s;
}
struct stack* push(struct stack *s, int x){
	struct stack *p, *q;
	q = s;
	p = (struct stack*)malloc(sizeof(struct stack));
	p->element = x;
	p->next = q;
	s = p;
	return s;
}

int main(){
	struct stack *S=NULL;
	int num;
	while (1){
		cin>>num;
		if (num==0){
			cout<<top(S)<<endl;
			S = pop(S);
		} else{
			S=push(S, num);
		}
	}
	return 0;
}

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