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 <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair
typedef long long LL;
#define EPS (1e-6)
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef pair<double,double> P;

bool isCross(P p1, P p2, P p3, P p4){
  double c = ((p1.first - p2.first) * (p3.second - p1.second) + (p1.second - p2.second) * (p1.first - p3.first)) * 
    ((p1.first - p2.first) * (p4.second - p1.second) + (p1.second - p2.second) * (p1.first - p4.first));
  if(c<=0.0)
    return true;
  return false;
}

int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(3);

  int INF = 1000000;

  stack<int> rail;

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

    }
  }
  


  return 0;
}

C++: #include <stdio.h>
int main(){
    int stay[10];
    int out[100];
    int i=0, k=0, j=0,n;
    while(scanf("%d",&n) != EOF){
        if(n==0){
            out[k]=stay[i-1];
            k++;
            //stay[i]=stay[i-2];
            i--;
        }else{
            stay[i]=n;
            i++;
        }
    }
    for(j=0;j<k;j++){
        printf("%d?\n",out[j]);
    }
    return 0;
}

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

int main(){
	int n,count = 0;
	stack<int> get;
	while(cin >> n){
		if(n==0){
			cout <<  get.top() << endl;
			get.pop();
			count -= 1;
		}
		else{
			get.push(n);
			count += 1;
		}
	}
	return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define llong long long

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

C++: #include <iostream>

using namespace std;

int main(){
        int *x; 
        int _x[10];
        x = _x; 
        int in = 0;
        while(cin >> in){
                if(!in){
                        cout << *(x-1) << endl;
                        x--;
                }else{
                        *x = in; 
                        x++;
                }   
        }   
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
void pop(int *i,int *a){
	cout<<*a<<endl;
	*i-=1;
	*a=0;
}
void push(int *i,int *a,int n){
	*a=n;
	*i+=1;
}
int main(){
	int a[100],i,n,j,k,p;

	for(i=0;i<100;i++){
		a[i]=0;
	}
	i=0;
	while(cin>>n){
		if(n==0){
			pop(&i,&a[i-1]);
		}else{
			push(&i,&a[i],n);
		}
	}
    return 0;
}

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

using namespace std;

int main(){

    vector<int> v;
    int n;

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

    return 0;
}

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

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

int main()
{
	stack<int> car;
	vector<int> outlist;

	while( !car.empty() || outlist.empty() )
	{
		int carnum;
		cin >> carnum;
		if(carnum!=0)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}

	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

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

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

C++: #include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <istream>
#include <iomanip>
 
#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif


int main(int argc, char **argv){
	std::vector<int> stack;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

#if INPUT_FROM_FILE
	while(std::getline(ifs, buf)){
#else
	while(std::getline(std::cin, buf)){
#endif
		int n = std::stoi(buf);

		if(n != 0){
			stack.push_back(n);
		}
		else{
			std::cout << stack.back() << std::endl;
			stack.pop_back();
		}
	}
	return 0;
}

C++: #include <stdio.h>

int train[10];
int sp = 0;

int empty() {
  return sp <= 0;
}

int size() {
  return sp;
}

int top() {
  return train[sp-1];
}

void pop() {
  sp--;
}

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

int main(){
  int num;
  while(1){
    scanf("%d", &num);
    if(num == 0){
      printf("%d\n", top());
      pop();
    }else{
      push(num);
    }
    if(size() == 0) break;
  }
  return 0;
}

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

int main(){
	vector<int> car, exit;
	int n;
	
	while( cin >> n ){
		
		if(n==0){
			exit.push_back( car.back());
			car.pop_back();
		}else{
			car.push_back(n);
		}
		if(car.size()==0) break;
	}
	vector<int>::iterator it = exit.begin();

	while( it != exit.end() ){
		cout << *it << endl;
		++it;
	}
	return 0;
}

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

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

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

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

int main()
{
	vector<int> train;
	for (int i = 0, n; i < 10 && cin >> n;) {
		switch (n) {
		case 0:
			cout << train.back() << endl;
			train.pop_back();
			i++;
			break;
		default:
			train.push_back(n);
		}
	}
	return 0;
}

C++: #include<stdio.h>
int i=0,j=0;
int cars[19];

int main(){
    while(1)
    {

        if(scanf("%d",&cars[i])==-1)
        {
            break;
        }
        if(cars[i]==0){
            printf("%d\n",cars[i-1]);
            i--;
        }
        else
        {
            i++;
        }
    }
    return 0;
}

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

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