Go: package main

import "fmt"

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

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

using namespace std;

stack<int>s;

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

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	stack<int> a;
	for (int b; cin >> b;) {
		if (b)a.push(b);
		else { cout << a.top() << endl; a.pop(); }
	}
	return 0;
}

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

int main()
{
        queue<int> op;
        queue<int> carrec;
        stack<int> car;
        int ops;
        int reccar;

        while(cin >> ops){
                op.push(ops);
        }

        while(!op.empty()){
                ops = op.front(); op.pop();
                if(ops != 0){
                        car.push(ops);
                }else if(ops == 0){
                        reccar = car.top();
                        carrec.push(reccar);
                        car.pop();
                }
        }

        while(!carrec.empty()){
                cout << carrec.front() << endl;
                carrec.pop();
        }

        return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>
#include <stack>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int in;
  stack<int> s;

  while(scanf("%d", &in) != EOF){
    if(in == 0){
      printf("%d\n",s.top());
      s.pop();
    }
    else s.push(in);
  }

  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(scanf("%d",	&k) != EOF){
		push(k);
		if(k	==	0){
			pop(train);
			outtrain[cnt]	=	result;
			cnt++;
			i	-=	2;
		}
	}
	for(k	=	0;	k	<=	cnt;	k++){
		if(outtrain[k]	!=	0)printf("%d\n",	outtrain[k]);
	}
	return 0;
}

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


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

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

	return 0;
}

C++: #include <stdio.h>

#define N 20
int main(void){
    int stk[N], sp=0;
    int n;
   
    for (int i=0; i<N; i++) stk[i]=0;
    while (scanf("%d", &n)){
        if (n==0 && sp!=0){
            printf("%d\n", stk[--sp]);
        } else {
            stk[sp++] = n;
        }
    }
    return 0;
}

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

using namespace std;

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

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

int main()
{
	stack<int> R;
	int n;
	int car[1000];
	int i = 0;
	
	while (cin >> n){
		if (n == 0){
			car[i] = R.top();
			R.pop();
			i++;
		}
		else {
			R.push(n);
		}
	}
	
	for (int j = 0; j < i; j++){
		cout << car[j] << endl;
	}
	
	return (0);
}

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

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

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

int main(){
	vector<int> train;
	int n;
	while(cin >> n){
		if(n!=0){
			train.push_back(n);
		}
		else{
			cout << train.back() << endl;;
			train.pop_back();
		}
	}
	return 0;
}

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

struct stack{
	int element;
	struct stack *next;
};
int top(struct stack *s){
	return s->element;
}
struct stack* pop(struct stack *s){
	struct stack *p, *q;
	q = s;
	p = s->next;
	free(q);
	s = p;
	return s;
}
struct stack* push(struct stack *s, int x){
	struct stack *p, *q;
	q = s;
	p = (struct stack*)malloc(sizeof(struct stack));
	p->element = x;
	p->next = q;
	s = p;
	return s;
}

int main(){
	struct stack *S=NULL;
	int num;
	while (1){
		cin>>num;
		if (num==0){
			cout<<top(S)<<endl;
			S = pop(S);
		} else{
			S=push(S, num);
		}
	}
	return 0;
}

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

C++: #include<stdio.h>
const int SIZE=100;
int data[SIZE];
int sp=0;
int size(){
  return sp;
}
int empty(){
  return sp<=0;
}
int top(){
  return data[sp-1];
}
void pop(){
  sp--;
}
void push(int v){
  data[sp]=v;
  sp++;
}
int main(){
  int n,k;
  while(n!=EOF){
    scanf("%d",&n);
    if(n==0){
      printf("%d\n",top());
      pop();
    }else{
      push(n);
    }
  }
  return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
	int in[10];
	int i = 0;

	while (scanf("%d", &in[i]) != EOF){
		if (in[i] == 0){
			i--;
			printf("%d\n", in[i]);
		}
		else {
			i++;
		}
	}
}

C++: #include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;
int main(){
  int train[10],n,i;
  n = 0;
  int order[30],intrain[10];
  for( i = 1;i <= 10;i++){
    train[i] = i;
  }
  for(i=0;i<30;i++)
    order[i] = 11;
  i = 0;
  while(scanf("%d",&order[i]) != EOF){i++;}
  for(i = 0;order[i] != 11;i++){
    if(order[i] != 0){
      intrain[n] = order[i]; n++;}else if(order[i] == 0){
      n--;      cout << intrain[n] << endl;}
  }
}

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

using namespace std;

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

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;




signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	deque<int> d;
	while (1) {
		int k;
		cin >> k;
		if (cin.eof()) break;
		if (k == 0) {
			cout << d.back() << endl;
			d.pop_back();
		}
		else {
			d.push_back(k);
		}
	}
}