Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	n, err := strconv.Atoi(nextString())
	return n, err
}

func main() {
	scanner.Split(bufio.ScanWords)

	stack := []int{}
	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		if n == 0 { // pop
			fmt.Println(stack[len(stack)-1])
			stack = stack[0:(len(stack) - 1)]
		} else { // push
			stack = append(stack, n)
		}
	}
}

C++: #include <stdio.h>

#include <string.h>

#include <stack>

#include <iostream>


using namespace std;

int main(){
    
    int input;
    stack<int> train;
    while (scanf("%d",&input)!=EOF) {
//        scanf("%d",&input);
        if (input!=0)train.push(input);
        else {
            printf("%d",train.top());
            train.pop();
        }
    }
}
    //        if(strcmp(c,pu) == 0){
    //
    //            scanf("%s",&color);
    //
    //            st.push(color);
    //
    //        }
    //
    //        if(strcmp(c,po) == 0){
    //
    //            cout<<st.top()<<endl;
    //
    //            st.pop();
    //
    //        }
    //
    //        if(strcmp(c,qu) == 0){
    //
    //            return 0;
    //
    //        }
    //
    //    }
    
    //}

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

int main(){
	std::stack<int> switching_rail;
	int car_number;
	
	while(std::cin >> car_number){
		if(car_number == 0){
			std::cout << switching_rail.top();
			switching_rail.pop();
		}
		switching_rail.push(car_number);
	}
	
	return 0;
}

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

int main(void)
{
	std::vector<int> incar;

	int n;

	while(std::cin >> n)
	{
		size_t isize=incar.size(); 
		if(n==0)
		{
			//outcar.push_back(incar[isize-1]);
			std::cout << incar[isize-1] << '\n';

			incar.pop_back();
		}
		else
		{
			incar.push_back(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;
}