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<cstdio>
#include<stack>
#include<algorithm>
using namespace std;
int main(void){
    int j=0;
	int k;
	int b[1000]={0};
	stack<int> a;
	a.push(-1);
	for(int i=0;;i++){
        if(i>=1&&a.top()==-1)break;
        cin>>k;

        if(k==0){
            cout<<a.top()<<endl;

            a.pop();
        }
        else a.push(k);
	}
	/*for(int i=0;i<j;i++){
        cout<<b[i]<<endl;
	}
*/

	return 0;
}

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

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

int main(void)
{
	int car[20] = {0};
	int cnt0 = 0;

	for(int i = 1; i <= 20; i++) {
		cin >> car[i - 1];
		if(car[i - 1] == 0)
			cnt0++;
		if(i % 2 == 0 && cnt0 == i / 2)
			break;
	}

	while(cnt0) {
		for(int i = 0; i + 1 < cnt0 * 2; i++) {
			if(car[i] != 0 && car[i + 1] == 0) {
				cout << car[i] << endl;
				for(int j = i; j < cnt0 * 2 - 2; j++)
					car[j] = car[j + 2];
				cnt0--;
				break;
			}
		}
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  int stack[10];
  int num = 0;
  int input;
  while (cin >> input) {
    if (input == 0) {
      cout << stack[--num] << endl;
    } else {
      stack[num++] = input;
    }
  }
  return 0;
}

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

//const static double	de_PI	= 3.14159265358979323846;
//const static int	de_MOD	= 1000000007;
//const static int	de_MAX	= 999999999;
//const static int	de_MIN = -999999999;

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());

	int n = 0;
	std::stack<int> S;
	std::vector<int> ans;

	while (std::cin >> n) {
		if (n != 0) {
			S.push(n);
		}
		else {
			ans.push_back(S.top());
			S.pop();
		}
	}

	for (int i = 0; i < ans.size(); i++) {
		std::cout << ans[i] << std::endl;
	}

}

C++: #include<stdio.h>

int main(){
  int i = 0, x;
  int data[100];
  while(x != EOF){
    scanf("%d", &x);
    if(x != 0){
      data[i] = x;
      i++;
    }else{
      printf("%d\n", data[i-1]);
      i--;
    }
  }
  return 0;
}

C++: 

#include <cstdio>
#include <bitset>
#include <cmath>
#include <complex>
#include <vector>
#include <algorithm>
#include <stack>

#define EPS 1e-6

using namespace std;
typedef complex<double> coor;

double cross(coor a, coor b)
{
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(coor a, coor b)
{
  return a.real() * b.real() + a.imag() * b.imag();
}

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

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


int main(int argc, char *argv[])
{
  stack<int> s;
  vector<int> m;
  while(cin>>a){
    if(a == 0){
      m.push_back(s.top());
      s.pop();
    }else{
    s.push(a);
	}
  }
  int S = m.size();
  for(int i= 0;i < S;i++){
    cout<<m[i]<< endl;
  }
  return 0;
}

C++: #include <cstdio>

int stack[10];
int cur = 0;

void push(int x){
	stack[cur] = x;
	cur++;
}

int pop(){
	cur--;
	return stack[cur];
}

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

C++: #include<iostream>
#include<stack>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)

using namespace std;


int main(){
	stack<int> rail;
	int num;

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


}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <stack>
using namespace std;
int main(){
  int n;
  stack<int> in,out;
  while(cin>>n){
    if(!n)out.push(in.top()),in.pop();
    else{in.push(n);}
    if(in.empty()&&!out.empty())break;
  }
  while(!out.empty()){
    cout<<out.top()<<endl;
    out.pop();
  }
  return 0;
}

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


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

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


	return 0;
}

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

using namespace std;

int main()
{
    int num;
    stack<int> rail;

    while (cin >> num) {
        if (num > 0) {
            rail.push(num);
        }
        else {
            cout << rail.top() << "\n";
            rail.pop();
        }
    }

    return 0;
}

C++: n,*a=&n;main(){for(;~scanf("%s",a);)*a%8?a++:puts(--a);}

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

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

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

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

signed main() {
	vector<int>a;
	int b;
	while (cin >> b) {
		if (b)a.push_back(b);
		else { cout << a[a.size() - 1] << endl; a.pop_back(); }
	}
}

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

int main() {
	vector<int>v;
	vector<int>::iterator pv=v.begin();
	int n;
	while (cin>>n) {
		if (n == 0) {
			int x = v.size();
			cout << v[x - 1] << endl;
			v.pop_back();
		}
		v.push_back(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 <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

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

    int input;
    stack<int> sta;

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

    return 0;
}