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 <stdio.h>

#define N 20
int main(void){
    int stk[N], sp=0;
    int n;
   
    while (scanf("%d", &n) != EOF){
        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 in, out;
	stack<int> stk;
	while( cin >> in ){
		
		if(in != 0){
			stk.push(in);
		}else{
			out = stk.top();
			cout << out << endl;
			stk.pop();
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> a;
  int box;
  while(1){
    cin >> box;
    if(box){
      a.push(box);
    }else{
      cout << a.top() << endl;
      a.pop();
    }
    if(a.empty())break;
  }
}

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

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

C++: #include<stdio.h>
int main(){
	int a,b,c,d,train[100];
	b=0;
	c=0;
	
	int g;
	int cont = 0;
	
	for(a=0;a<1000;a++){
		scanf("%d",&g);
		
		if(g != 0){
			train[cont] = g;
			cont++;
		}
		else{
			printf("%d\n",train[cont-1]);
			cont--;
		}
		
		if(cont == 0){
			break;
		}
		/*
		if(train[a]==0){
			c++;
		}else{
			b++;
		}
		if(b==c){
		break;
		} 
		*/
	}
	return 0;
}

C++: #include <stdio.h>
#include <stack>

int main() {
	int space;
	std::stack<int> st;
	scanf("%d", &space);
	st.push(space);
	while(! st.empty()) {
		scanf("%d", &space);
		if(space != 0) {
			st.push(space);
		} else {
			printf("%d\n", st.top());
			st.pop();
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
  int val;
  stack<int> stk;

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

  return 0;
}

C++: #include <iostream>

using namespace std;

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

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

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

C++: #include<iostream>
#include<stack>
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<stdio.h> 
#include<stack> 
int main(){
	std::stack<int> s;     
	int n;     
	scanf("%d",&n);     
	s.push(n);     
	while(!s.empty()){         
		scanf("%d",&n);         
		if(n!=0)s.push(n);         
		else{             
			printf("%d\n",s.top());             
			s.pop();         
		}     
	} 
}

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

int main() {
	int in;
	vector <int> a;
	while (1) {
		cin >> in;
		if (in == 0) {
			cout << a[a.size() - 1];
			a.erase(a.end() - 1);
			if (a.size() == 0) {
				cout << endl;
				break;
			}
			else
				cout << endl;
		}
		else
			a.push_back(in);
	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

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

int main(){
	int k;
	stack<int> q;

	cin >> k;
	q.push(k);

	while (1){
		cin >> k;
		if (k != 0)
			q.push(k);
		else{
			printf("%d\n", q.top());
			q.pop();
		}
		if (q.empty())
			break;
	}
}

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

int main(){
	stack<int> st;
	queue<int> q;
	int input;

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

}

C++: #include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main(void)
{
  stack<int> in;
  queue<int> out;
  int n,c;
  cin>>c;
  in.push(c);
  while(!in.empty())
  {
    cin>>c;
    if(c==0){
      out.push(in.top());in.pop();
    }else{
      in.push(c);
    }
  }
  while(!out.empty())
  {
    cout<<out.front()<<endl;
    out.pop();
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.SRC", "r", stdin );
	string str = "";
	stack<int> st;
	while (getline (cin, str ) ){
		stringstream ss (str );
		int car = -1;
		ss >> car;
		if (car != 0 ){
			st.push (car );
		}else{
			cout << st.top() << endl;
			st.pop();
		} // end if
	} // end while
		
	return 0;
}

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

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	stack<int> S;
	int n;
	cin >> n;
	S.push(n);

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