Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	n, err := strconv.Atoi(nextString())
	return n, err
}

func main() {
	scanner.Split(bufio.ScanWords)

	stack := []int{}
	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		if n == 0 { // pop
			fmt.Println(stack[len(stack)-1])
			stack = stack[0:(len(stack) - 1)]
		} else { // push
			stack = append(stack, n)
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void)
{
    int a[110][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[101] = {0};
    bool judge = true;
    int tempjudge = 0;
    
    while(judge)
    {
        cin >> a[i][0];
        if(a[i][0] == 0)
        {
            a[i][1] = 1;
            RFOR(j,i,-1)
                if(a[j][1] != 1 )
                {
                    answer[l] = a[j][0];
                    a[j][1] = 1;
                    cout << answer[l] << endl;
                    l++;
                    break;
                }
        }
        REP(k,i+1)
        if(a[k][1] != 1){
                judge = true;
                break;
        }
        else
            judge = false;
                
        
        i++;
    }

    return 0;
}

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

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 ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
typedef long long ll;

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

	}
	return 0;
}

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

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

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void)
{
  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 <iostream>
using namespace std;

int main() {
	
	int clear = 0;
	int n , m[12] = {} ;
	
	while( cin >> n ){
		if( n==0 ){
			for( int i=11 ; i>=0 ; i-- ){
				if( m[i] != 0 ){
					cout << m[i] << endl ;
					m[i] = 0 ;
					if( i==0 ) clear = 1 ;
					break ;
				}
			}
		}
		else {
			for( int i=0 ; i<12 ; i++ ){
				if( m[i] == 0 ){
					m[i] = n ;
					break ;
				}
			}
		}
		if( clear != 0 ) break ;
	}
	
	return 0;
}

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

using namespace std;



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

C++: #include <stdio.h>

int main(){
	int i=0, n;
	int a[30];
	for(int i=0 ; i<30 ; i++){
		a[i] = 0;
	}
	
	while( scanf("%d", &n) != EOF ){
		
		if(n==0){
			i--;
			printf("%d\n" , a[i]);
		}else{
			a[i] = n;
			i++;
		}
		if(i==0) break;
	}
	
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <vector>
int main(){
  std::stack<int> i;
  std::vector<int> o;
  int n;
  while(std::cin>>n){
    if(!n)o.push_back(i.top()),i.pop();
    else{i.push(n);}
    if(i.empty()&&!o.empty())break;
  }
  std::vector<int>::iterator it = o.begin();
  while(it!=o.end()){
    std::cout<<*it<<std::endl;
    it++;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int now=-1;
	int n[10]={0};
	int in;
	for(;;){
		cin>>in;
		if(in==0){
			cout<<n[now];
			now--;
			if(now==-1)return 0;
		}
		else{
			n[now+1]=in;
			now++;
		}
	}
}

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

using namespace std;

int main()
{
	int n;
	vector<int> train;
	while (cin >> n) {
		if (n) {
			train.push_back(n);
		}
		else {
			cout << train.back() << endl;
			train.pop_back();
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<stack>
using namespace std;

int main(){
	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++: const int N=10;
using namespace std;


int main(){
    int a[N];
    int n=0;
    while (!cin.eof()){
        int t;
        cin>>t;
        if (t) a[n++]=t;
        else cout<<a[--n]<<endl;
    }
    return 0;
}

C++: //↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


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

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

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

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

int main() {
  stack<int> c;
  queue<int> q;

  int n;
  while(cin >> n) {
    if(n == 0) {
      int s = c.top();
      q.push(s);
      c.pop();
    }else {
      c.push(n);
    }
  }

  while(!q.empty()) {
    cout << q.front() << endl;
    q.pop();
  }

  return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

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

C++: // -*- coding: utf-8 -*-
// Last-Updated : <2014/06/19 18:20:36 by samui>

#include <iostream>
#include <cstdio>
#include <string>

#include <vector>

int main(int argc, char **argv){
  int a;
  std::vector<int> b;
  while(std::cin >>a){
    if(a == 0){
      std::cout<<b[b.size()-1]<<std::endl;
      b.pop_back();
    }else{
      b.push_back(a);
    }

  }
  return 0;
}