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 <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>

using namespace std;

int main() {

	stack<int> st;
	int a, ans[100]={0},i = 0;

	while (1) {
		cin >> a;
		if (a == 0) {
			ans[i] = st.top();
			st.pop();
			i++;
			if (st.empty())
				break;
		}
		else {
			st.push(a);
		}
	}

	for (int j = 0; j < i; j++) {
		cout << ans[j] << endl;
	}

	return 0;
}

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

using namespace std;
int main(int ac, char **av) {
  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<iostream>
using namespace std;
int b[1000000];
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++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    int a;
    vector<int> s;
    vector<int> t;
    while(cin>>a){
        if(a!=0){
            s.push_back(a);
        }else{
            s.pop_back(a);
            t.push_back(s[s.size()-1]);
            s.pop_back(s[s.size()-1]);
        }
    }
    for(int i=0;i<t.size();i++){
        cout << t[i] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
int main() {
	int num, retu=0;
		int *train = new int[10];
		while (cin >> num) {
			if (num == 0) {
				cout << train[retu-1]<<endl;
				retu--;
			}
			else {
				train[retu] = num;
					retu++;
			}
	}
	return 0;
}

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

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

	string kotae = "";
	while ( S.empty() == false )
	{
		int n;
		cin >> n;
		if ( n == 0 )
		{
			ostringstream os;
			os << S.top() << endl;
			kotae += os.str();
			S.pop();
		}
		else
		{
			S.push( n );
		}
	}

	cout << kotae << endl;

	return 0;
}

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


int main()
{
    std::stack<int> Stack;
    while(true){
        int n;
        std::cin >> n;
        if(n == 0){
            assert(Stack.empty() == false);
            std::cout << Stack.top() << std::endl;
            Stack.pop();
        }else{
            Stack.push(n);
        }
        if(std::cin.eof()) break;
    }
    return 0;
}

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

using namespace std;

int main() {
    int x;
    stack<int> stack;

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

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

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	vector<int>in;
	while(cin>>n){
		if(n)in.pb(n);
		else {
			cout<<in[in.size()-1]<<endl;
			in.erase(in.end()-1);
		}
	}
}

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

	return 0;
}

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


int main(){
    using namespace std;

    stack<int>s;
    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 <cstdio>
#include <stack>

using namespace std;

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

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

int main(void) {
    int stack[100];
    int tail = 0;
    int n;
    while(cin >> n) {
        if(n) {
            stack[tail++] = n;
        } else {
            cout << stack[--tail] << endl;
        }
    }
}

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

using namespace std;

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

C++: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<stack>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int in;
  stack<int>out;
  while(cin>>in){
    if(in)out.push(in);
    else {
      cout<<out.top()<<endl;
      out.pop();
    }
  }


}

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

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

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

using namespace std;

stack<int> Stack;

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