Go: package main

import "fmt"

func main() {
	stack := []int{}
	for {
		var a int
		i, _ := fmt.Scan(&a)
		if i == 0 {
			break
		}
		if a == 0 {
			fmt.Println(stack[len(stack)-1])
			stack = stack[:len(stack)-1]
			continue
		}
		stack = append(stack, a)
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

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

    return 0;
}

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

using namespace std;

int main(){

  int train;
  stack<int> s;

  cin >> train;

  s.push(train);

  while(!s.empty()){

    cin >> train;

    if(train) s.push(train);
    else {
      cout << s.top() << endl;
      s.pop();
    }

  }

}

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

int main(){
    int n;
    int i=0;
    int s=55;
    int num[105];
    while(cin>>n){
        if(n==0){
            while(1){
                if(num[s]!=0){
                    cout<<num[s]<<endl;
                    num[s]=0;
                    s=55;
                    break;
                }
                s--;
            }

        }
        else {
            while(1){
                if(num[i]==0){
                    num[i]=n;
                    i=0;
                    break;
                }
                i++;
            }
        }
                }
    return 0;
    }

C++: #include <iostream>
#include <stack>
int main(){
  std::stack<int> i;
  int n=0;
  while(std::cin>>n){
    if(!n)std::cout<<i.top()<<std::endl,i.pop();
    else{i.push(n);}
  }
  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];
            i--;
            k++;
        }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() {
  stack<int> track;
  int n;
  while (cin >> n) {
    if (n == 0) {
      cout << track.top() << endl;
      track.pop();
      continue;
    }
    track.push(n);
  }
}

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

int main ()
{
    std::stack<u_int> cars;
    u_int number;

    while(std::cin >> number){
        if(number != 0){
            cars.push(number);
        }else{
            std::cout << cars.top() << std::endl;
            cars.pop();
        }
    }
    
    return 0;
}

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

using namespace std;

int main(){
	vector<int> stack, seq;
	int n;

	while(cin >> n){
		if(cin.eof()){
			break;
		}
		if(n == 0){
			seq.push_back(stack.back());
			stack.pop_back();
		}else{
			stack.push_back(n);
		}
	}
	for(int& n : seq){
		cout << n << endl;
	}
}

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

using namespace std;

int main() {
    stack<int> st;
    int t;

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

    return 0;
}

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



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

while(cin>>d){

if(d!=0) {
a.push(d);
}
else {
cout<<a.top()<<endl;
a.pop();
}
}

}

C++: #include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<stack>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

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

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

  }
}

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;
	}

}