Go: package main

import (
        "fmt"
)

func main() {
        var stk [101]int
        var c int
        pvt := 0
        for {
                _, err := fmt.Scanf("%d", &c)
                if err != nil {
                        break
                }
                if c > 0 {
                        stk[pvt] = c
                        pvt++
                } else {
                        pvt--
                        fmt.Printf("%d\n", stk[pvt])
                }
        }
}

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

using namespace std;

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

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

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

	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
#define FOR(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

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

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

int main(){

	std::stack<int> train;

	int buf;

	while(std::cin >> buf){

		if(buf == 0){

			std::cout << train.top() << std::endl;
			train.pop();

		}else{

			train.push(buf);

		}
	
	}

	return 0;
}

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

int main() {
  int order,i;
  int syako[1000];
  i=0;
  while(cin >> order) {
    if(order != 0) {
      syako[i] = order;
      i++;
    }
    else {
      cout << syako[i-1] << endl;
      i--;
    }
  }
}

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

using namespace std;

int main()
{
	stack<int> in,out;
	int i;
	while(cin>>i){
		if(i)	in.push(i);
		else	out.push(in.top()),in.pop();
	}
	while(!out.empty())	in.push(out.top()),out.pop();	// reverse
	while(!in.empty()){
		printf("%d\n",in.top());
		in.pop();
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main()
{
	vector<int> garage;
	vector<int> outgoing;
	int data;
	int train;
	while(cin>>train)
	{
		if(0==train)
		{
			outgoing.push_back(garage.back());
			garage.pop_back();
		}
		else
		{
			garage.push_back(train);
		}
	}
	for(int i=0;i<outgoing.size();++i)
	{
		cout<<outgoing[i]<<endl;
	}
}

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

int main()
{
	stack<int> s;
	deque<int> ans;
	int n;

	while (cin >> n)
	{
		if (cin.eof()) return 0;
		if (n == 0)
		{
			ans.push_front(s.top());
			s.pop();
			//if (s.empty()) break;
		}
		else
		{
			s.push(n);
		}
	}

	while (1)
	{
		if (!ans.empty())
		{
			cout << ans.back() << endl;
			ans.pop_back();
		}
		else break;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;






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

C++: #include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    vector<int> ans;
    stack<int> stk;
    int v;
    while(cin>>v){
        if(v==0){
            ans.pb(stk.top());
            stk.pop();
        }else{
            stk.push(v);
        }
    }
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
    return 0;
}

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

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

C++: #include<stdio.h>
#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{
			printf("%d\n",s.top());
			s.pop();
		}
	}
	return 0;
}

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

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

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

using namespace std;

int main()
{
	int train;
	stack<int> rail;

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

	return 0;
}

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

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

C++: #include<iostream>
int main(){for(int n,t[10],*p=t;!(std::cin>>n).eof();)n?*p++=n:printf("%d\n",*--p);}

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

int main(void){

  int i = 0;
  int n;
  stack<int> Stack;
  vector<int>array(ARRAY_MAX,0);

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