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>

using namespace std;

int main() {

	int i, j=0, n, a[10], b[10];

	for(i=0; i<10; i++) {
		b[i]=0;
	}

	i=0;
	while(1) {
		cin >> n;
		if(n==0) {
			b[j]=a[i-1];
			j++;
			i--;
			a[i]=n;
			if(i==0)
				break;
			continue;
		}
		a[i]=n;
		i++;
	}

	for(i=0; b[i]!=0; i++) {
		cout << b[i] << endl;
	}

	return 0;

}

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

int main(){
  stack<int> s;
  int n;
  while(scanf("%d",&n) != EOF){
    if(n != 0) s.push(n);
    else{
      cout << s.top()<<endl;
      s.pop();
    }
  }
  return 0;
}

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

using namespace std;

int main()
{
    stack<int> st;

    int a;

    cin >> a;
    st.push(a);

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

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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

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

C++: #include<iostream>
using namespace std;
int b[10000000];
int main(){
  int i=0,num,a[10],x=0;
  
  while(cin>>num){
    if(num==0){
      b[x++]=a[i-1];
      i--;
    }
    else  a[i++]=num;
    if(!i)break;
  }
  
  for(i=0;i<x;i++)
    cout<<b[i]<<endl;
  return 0;
}

C++: // 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
#ifdef DAIJOBU
#include "/home/v-o_o-v/deb.h"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif 

using namespace std;

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

	int n;
	vector<int> v;
	while(cin >> n){
		if(n == 0){
			cout << v.back() << '\n';
			v.pop_back();
		}else v.push_back(n);
	}
	return 0;
}
// Write Here

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

int main() {
	int n[50], x, i=0,flag=0,check=0;
	for (;;) {
		cin >> x;
		if (x == 0 && flag == 1) {
			i--;
			cout << n[i - 1];
			flag = 1;
			check = 1;
		}
		else if (x == 0) {
			cout << n[i - 1];
			flag = 1;
			check = 1;
		}
		else if (x > 0) {
			if (check == 1) {
				i--;
				check = 0;
			}
			n[i] = x;
			i++;
			flag = 0;
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
#include <stack>

using namespace std;
double T_area(double x1,double y1, double x2, double y2, double x3, double y3);

int main(){
    stack<int> st;    // int型のスタック
    int n;
    while(scanf("%d",&n)!=EOF){
        if(n!=0){
            st.push(n);
        }else{
            cout << st.top() << "\n";
            st.pop();
        }
    }
    
    
}

C++: #include <stdio.h>
int main() {int RB[105],last=0,i;while (scanf("%d",&i)!=EOF) {if (!i) printf("%d\n",RB[--last]); else RB[last++]=i;}return 0;}

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

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

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

int main()
{
    list<int> stack;

    for (int n; cin >> n;)
        if (n == 0) {
            cout << stack.front() << endl;
            stack.pop_front();
        } else
            stack.push_front(n);

    return 0;
}

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

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

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

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

int main() {
	std::stack<int> stCar;
	std::queue<int> qOut;
	int number;

	while (std::cin >> number) {
		if (number != 0) {
			stCar.push(number);
		} else {
			qOut.push(stCar.top());
			stCar.pop();
		}
	}

	while (!qOut.empty()) {
		std::cout << qOut.front() << '\n';
		qOut.pop();
	}
	return 0;
}

C++: #include <cstdio>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string> 
#include <vector> 
using namespace std;

int main(){
/*??¢??????????????¨40????????????
	string in[100],n;
	int i = 1,stop = 0,si;
	while(stop == 0){
		cin >> n;
		if(n == "#"){stop = 1;}else{in[i] = n;i++;}						
	}
	string ans[i];
	for(int ii = 1;i > ii;ii++){
		ans[ii] = "A";
		si = in[ii].size();
		for(int iii = 0;si > iii;iii++){
			string c = in[ii].substr(iii,1);
			      if(ans[ii] == "A"){
				if(c == "1"){
					ans[ii] = "Y";
				}else if(c == "0"){
					ans[ii] = "X";
				}
			}else if(ans[ii] == "X"){
				if(c == "1"){
					ans[ii] = "Z";
				}else if(c == "0"){
					ans[ii] = "No";
				}
			}else if(ans[ii] == "Y"){
				if(c == "1"){
					ans[ii] = "No";
				}else if(c == "0"){
					ans[ii] = "X";
				}
			}else if(ans[ii] == "Z"){
				if(c == "1"){
					ans[ii] = "B";
				}else if(c == "0"){
					ans[ii] = "W";
				}
			}else if(ans[ii] == "W"){
				if(c == "1"){
					ans[ii] = "Y";
				}else if(c == "0"){
					ans[ii] = "B";
				}
			}else if(ans[ii] == "B"){
				if(c == "1"){
					ans[ii] = "X";
				}else if(c == "0"){
					ans[ii] = "Y";
				}
			}	
			if(iii == si - 1 and ans[ii] == "B"){ans[ii] = "Yes";}
			if(iii == si - 1){
				if(ans[ii] != "Yes"){ans[ii] = "No";}
				cout << ans[ii] << endl;
			}											
		}
	}*/
	/*	int	X,Y[3],P,ANS[2];
		cin >> X >> Y[1] >> Y[2] >> Y[3] >> P;
		ANS[1] = P * X;
		cout << "[AiUEO]" << P << " " << X << endl;
		if(P > Y[2]){
			ANS[2] = Y[1] + ( Y[3] * ( P - Y[2] ) );
		}else{
			ANS[2] = Y[1];
		}
		if(ANS[1] > ANS[2]){
			cout << ANS[2] << endl;
			cout << ANS[1] << endl;
		}else{
			cout << ANS[2] << endl;
		}*/
//
    int num, top;
    int train[1024];
    int i;

    top = 0;

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

}

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

int main(){

  int stack[10] = {};
  int p = 0;

  while(cin >> stack[p]){
    if(stack[p] == 0){
      cout << stack[p-1] << endl;
      p--;
    }
    else{
      p++;
    }
  }
 
  return 0;
}

C++: #define scanf_s scanf
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 100
int main(void)
{
	int w, n, now = 0;
	int list[MAX] = { 0 };
	do{	
		scanf_s("%d", &n);
		if (n != 0) { list[now] = n; ++now; }
		else { --now; printf("%d\n", list[now]); }
	} while (now != 0);
}

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