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<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

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

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

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

C++: #include <iostream>
#include<iomanip>
#include <vector>
#include <algorithm>
#include<math.h>
using namespace std;

int main(){
	int n,a=0,b=0;
	while(true){
		cin>>n;
		if(n!=0){
			if(b==0)b=n;
			if(b!=0)a=n;
		}else{
			if(a!=0){
				cout<<a<<endl;
				a=0;
			}else if(a==0&&b!=0){
				cout<<b<<endl;
				b=0;
			}else if(a==0&&b==0){
				return 0;
			}
		}
	}
	return 0;
}

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

int main() {
	vector<int>v;
	vector<int>::iterator pv=v.begin();
	int n;
	while (cin >> n) {
		if (n == 0) {
			pv == v.end();
			cout << *pv << endl;
			v.pop_back();
		}
		v.push_back(n);		
	}
	return 0;
}

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

int main(){
  int x;
  queue<int> q;
  while(scanf("%d", &x) != EOF){
    if(x == 0){
      printf("%d\n", q.front());
      q.pop();
    }
    else{
      q.push(x);
    }
  }
  return 0;
}

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

int main()
{
	int d;
	stack<int> q;
	while(~scanf("%d",&d)){
		if(d==0){
			printf("%d\n",q.top());
			q.pop();
		}
		else{
			q.push(d);
		}
	}		
}

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

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

using namespace std;

const int N = 1000000;

int stack[N], top;

int main() {
	int n;
	top = 0;
	while (scanf("%d", &n) != EOF) {
		if (n) stack[top++] = n;
		else printf ("%d\n", stack[--top]);
	}
	return 0;
}

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

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

C++: #include<stdio.h>
int main(){
  int sp=0,data[99],n,i;
  for(i=0;i<100;i++){
    scanf("%d",&n);
    if(n==0){
      sp--;
      printf("%d\n",data[sp]);
    }else{
      data[sp]=n;
      sp++;
    }
  }
}

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

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

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

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

  while(cin >> n){
    if(n != 0){
      a.push(n);
    }
    else if(a.size() == 0){
      int div = 9 / 10;
      cout << 10 / div << endl;
    }
    else{
      cout << a.top() << endl;
      a.pop();
    }
  }
}

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

using namespace std;

int main(){
 	
  int t=0,p,m,n[10];
 while(cin>>m){

   if(m!=0){n[t]=m;t++;}
   if(m==0){cout<<n[t-1]<<endl;n[t]=11;t--;}
}

return 0;
}

C++: #include<stdio.h>
int main(){
int a[500];
int j,a=0;
for(int i=0;i<500;i++){
scanf("%d",&a[i]);
if(a[i]==0){
j=i;
while(a=0){
if(j-1!=0){
printf("%d\n",a[j-1]);
a=1;
}
j--;
}
a=0;
a[j]=0;
if(j==0){
i=501;
}
}
}
return 0;
}

C++: #include<iostream>

#define MAX 256

int main(void){
	
	int i=0,j=0;
	int a[MAX];
	int ans[MAX];
	while(cin>>x){
		if(x==0){
			ans[j]=a[i-1];
			j++;
			i--;
		}else{
			ans[i]=x;
			i++;
		}
		
		
	}
	
	for(int i=0;i<j;i++){
		cout<<ans[i]<<endl
	}
	
}

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

int main(){

  int x, t[10], cnt=0;

  while(cin>>x){
    if(x==0){
      cnt--;
      cout<<t[cnt]<<endl;
    }else{
      t[cnt]=x;
      cnt++;
    }
  }
  
  return 0;
}

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

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

int main()
{
	int n;
	int cnt = 0;
	stack<int> car;
	vector<int> out;

	while (cin >> n, cin.eof() != true){
		if (n == 0){
			out.push_back(car.top());
			car.pop();
		}
		else {
			car.push(n);
		}
	}

	for (int i = 0; i < out.size(); i++){
		cout << out[i] << endl;
	}

	return (0);
}

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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

stack<int> st;
int x;

signed main() {
    while(cin>>x){
        if(x)st.push(x);
        else {
            std::cout << st.top() << '\n';
            st.pop();
        }
    }



    return 0;
}

C++: const int IN = 20, OUT = 100;
int data1[IN], data2[OUT];
int spA = 0, spB = 0;
int top(){
  return data1[spA - 1];
}
void pop(){
  spA--;
}

#include<stdio.h>
int main(){
  int i, n, c;
  while((c = getchar()) != EOF){
    scanf("%d", &n);
    if(n != 0){
      data1[spA] = n;
      spA++;
    }else{
      data2[spB] = top() ;
      spB++;
      pop();
    }
  }
  for(i = 0; i < spB; i++){
    printf("%d\n",data2[i]);
  }
  return 0;
}

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

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

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

C++: #include<iostream>
#include<stack>
#include<cstdio>
using namespace std;
int main(){
  stack<int> train;
  int a;
   while(scanf("%d",&a)!=EOF){
    if(a==0){
    cout<<train.top()<<endl;
    train.pop();
    }
    else {
      train.push(a);
    }
  }
}

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

using namespace std;

int main(){
	stack<int> in;

    for(int n; cin >> n;)
        if(!n) cout << in.top() << endl, in.pop();
        else in.push(n);

	return 0;
}