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<stdio.h>
int main(){
  int sp=0,data[9],n,i;
  for(i=0;i<100;i++){
    scanf("%d",&n);
    if(n==0){
      printf("%d\n",data[sp]);
      sp--;
    }else{
      sp++;
      data[sp]=n;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
int main(){
	std::vector<int> car,ans;
	int a;
	while(std::cin>>a){
		if(a!=0)car.push_back(a);
		else {
			std::vector<int>::iterator it=car.end();
			int *n=&*it;
			car.pop_back();
			ans.push_back(*n);
		}
	}
	for(int i=0;i<ans.size();i++){
		std::cout<<ans[i]<<std::endl;
	}
	return 0;
}

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

int main() {
  int n;
  stack<int> stk;
  while (cin >> n) {
    if (n) {
      stk.push(n);
    } else {
      cout << stk.top() << "\n";
      stk.pop();
    }
  }
  return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	stack<int> T;
	int q;
	while(cin>>q){
		if(q){
			T.push(q);
		}
		else{
			out(T.top());
			T.pop();
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <math.h>

using namespace std;

class STACK{
public:
	STACK(){
		index = 0;
	}

	void push(int data){
		array[index] = data;
		index++;
	}
	int pop(){
		index--;
		return array[index];
	}
	bool isEmpty(){
		return index == 0;
	}

private:
	int array[100];
	int index;
};

int main(){

	STACK stack;
	int tmp;
	while(scanf("%d",&tmp) != EOF){
		if(tmp == 0){
			printf("%d\n",stack.pop());
		}else{
			stack.push(tmp);
		}
	}
    return 0;
}

C++: //#define _USE_MATH_DEFINES
#include <iostream>
//#include <stdio.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>
//#include <time.h>

using namespace std;


int main(){

	int a;
	vector <int> s;

	while (cin >> a){
		if (a == 0){
			cout << s.back() << endl;
			s.pop_back();
		}
		else{
			s.push_back(a);
		}
	}


	return 0;
}

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

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

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

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

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

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

C++: #include<cstdio>
int main()
{
    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<iostream>
#include<stack>
using namespace std;
int main(){
  stack<int> b;
  int n;
  while(cin>>n){
    if(n==0){
      cout<<b.top()<<endl;
      b.pop();
    }
    else b.push(n);
  }
  return 0; 
}

C++: #include <stdio.h>

#define N 20
int main(void){
    int stk[N], sp=0;
    int n;
   
    while (scanf("%d", &n) != EOF){
        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 in, out;
	stack<int> stk;
	while( cin >> in ){
		
		if(in != 0){
			stk.push(in);
		}else{
			out = stk.top();
			cout << out << endl;
			stk.pop();
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> a;
  int box;
  while(1){
    cin >> box;
    if(box){
      a.push(box);
    }else{
      cout << a.top() << endl;
      a.pop();
    }
    if(a.empty())break;
  }
}

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

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

C++: #include<stdio.h>
int main(){
	int a,b,c,d,train[100];
	b=0;
	c=0;
	
	int g;
	int cont = 0;
	
	for(a=0;a<1000;a++){
		scanf("%d",&g);
		
		if(g != 0){
			train[cont] = g;
			cont++;
		}
		else{
			printf("%d\n",train[cont-1]);
			cont--;
		}
		
		if(cont == 0){
			break;
		}
		/*
		if(train[a]==0){
			c++;
		}else{
			b++;
		}
		if(b==c){
		break;
		} 
		*/
	}
	return 0;
}

C++: #include <stdio.h>
#include <stack>

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

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

using namespace std;

int main()
{
  int val;
  stack<int> stk;

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

  return 0;
}

C++: #include <iostream>

using namespace std;

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

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

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

C++: #include<iostream>
#include<stack>
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<stdio.h> 
#include<stack> 
int main(){
	std::stack<int> s;     
	int n;     
	scanf("%d",&n);     
	s.push(n);     
	while(!s.empty()){         
		scanf("%d",&n);         
		if(n!=0)s.push(n);         
		else{             
			printf("%d\n",s.top());             
			s.pop();         
		}     
	} 
}