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 <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void)
{
    int a[110][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[101] = {0};
    bool judge = true;
    int tempjudge = 0;
    
    while(judge)
    {
        cin >> a[i][0];
        if(a[i][0] == 0)
        {
            a[i][1] = 1;
            RFOR(j,i,-1)
                if(a[j][1] != 1 )
                {
                    answer[l] = a[j][0];
                    a[j][1] = 1;
                    l++;
                    break;
                }
        }
        REP(k,i+1)
        if(a[k][1] != 1){
                judge = true;
                break;
        }
        else
            judge = false;
                
        
        i++;
    }
    REP(m,l)
    cout << answer[m] << endl;

    return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;

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

C++: #include <iostream>

using namespace std;
int main(){
  int a[100],k = 0,o;
  while(1){
    cin >> o;
    if(o == 0){
      cout << a[k-1] << endl;
      k--;
    } else {
      a[k++] = o;
   }
    if(k == 0)break;
  }
}

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

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

using namespace std;

int main()
{
    stack<int> st;

    int a;

    while (cin >> a) {
        if (a) st.push(a);
        else { cout << st.top() << endl; st.pop(); }
    }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void)
{
    int a[201][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[201] = {0};
    bool judge = true;
    int tempjudge = 0;
    
    while(judge)
    {
        cin >> a[i][0];
        if(a[i][0] == 0)
        {
            a[i][1] = 1;
            RFOR(j,i,-1)
                if(a[j][1] != 1 )
                {
                    answer[l] = a[j][0];
                    a[j][1] = 1;
                    cout << "ouput"<< answer[l] << endl;
                    l++;
                    break;
                }
        }
        REP(k,i+1)
        if(a[k][1] != 1){
                judge = true;
                break;
        }
        else
            judge = false;
                
        
        i++;
    }

    return 0;
}

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

using namespace std;

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

C++: #include <stdio.h>
#include <vector>
using namespace std;

int main(){
	vector<int> hoge;
	int n;
	
	while( scanf("%d", &n) != EOF ){
		
		if(n==0){
			printf("%d\n" , hoge.back());
			hoge.pop_back();
		}else{
			hoge.push_back(n);
		}
		if(hoge.size()==0) break;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

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

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

C++: #include <stdio.h>

int main() {
	int a,i,k,m;
	int data[15] = {0};
	int output[15] = {0};
	for (i = 0; i < 15; i++) {
		scanf("%d", &a);
		if (a != 0) {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					data[k] = a;
					break;
				}
			}
		}
		else {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					for (m = 0; m < 15; m++) {
						if (output[m] == 0) {
							output[m] = data[k - 1];
							break;
						}
					}
					data[k - 1] = 0;
					break;
				}
			}
		}
	}
	printf("\n");
	for (i = 0; i < 15; i++) {
		if (output[i] != 0) {
			printf("%d\n", output[i]);
		}
	}
	return 0;
}

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

int main(){
	std::stack<int> railroad;
	
	int incar; 
	while(std::cin >> incar){
		if(incar != 0){
			// in
			railroad.push(incar);
		}else{
			// out
			std::cout << railroad.top() << std::endl;
			railroad.pop();
		}
	}
	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(1){
		scanf("%d",	&k);
		push(k);
		if(k	==	0){
			pop(train);
			outtrain[cnt]	=	result;
			cnt++;
			i	-=	2;
		}
		if(i	==	0)break;
	}
	for(k	=	0;	k	<=	cnt;	k++){
		if(outtrain[k]	!=	0)printf("%d\n",	outtrain[k]);
	}
	return 0;
}

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

C++: #include<bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く 
　　提出する問題を間違えない */
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
int main(){
  stack<int> train;
  int a;
  while(1){
    cin >> a;
    if(a){
      //if(cin.eof())break;
      train.push(a);
    }else{
      cout << train.top() << endl;
      train.pop();
      if(train.empty())break;
    }
  }
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;

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

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

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

using namespace std;

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