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*****/
#include <iostream>
#include <fstream>
#include <list>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	list<int> V;
	int order;
	/*****処理部*****/
	while(1){
		cin >> order;
		if(order == 0){
			cout << V.back() << endl;
			V.pop_back();
		}else{
			V.push_back(order);
		}
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

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

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

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

int main(){
	vector<int> v;
	stack<int> s;
	int n;
	cin >> n;
	s.push(n);
	while(cin>>n){
		if(n==0){
			v.push_back(s.top());
			s.pop();
		} else {
			s.push(n);
		}
	}
	for(int i=0 ; i<v.size(); i++){
		cout << v[i] << endl;
	}
	return 0;	
}

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

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

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

using namespace std;

stack<int> s;
int ac;

int main(void) {
    s.clear();
    while(~scanf("%d", &ac)) {
        if(ac == 0) {
            cout << s.top() << endl;
            s.pop();
        } else {
            s.push(ac);
        }
    }
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

int data;
stack<int> st;

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

  return 0;
}

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

int main(){
	int in,tmp;
	stack<int> st;
	cin>>tmp;
	st.push(tmp);
	while(st.empty()==false){
		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 input[20];
	int output[10];
	int temp[10];
	int i;
	int j = 0;
	int k = 0;

	for(i = 0; i < 20; i++)
		input[i] = 11;

	i = 0;
	while(scanf("%d", &input[i]) != EOF) i++;

	i = 0;
	while(input[i] != 11) {
		if(input[i] != 0) {
			temp[j] = input[i];
			j++;
		}

		else {
			j--;
			output[k] = temp[j];
			k++;
		}

		i++;
	}

	for (i = 0; i < k; i++)
		printf("%d\n", output[i]);
	
	return 0;
}

C++: #include <stdio.h>

int n ;
int p ;
int stack[15] ;

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

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


int main(){

  int train , n[10] , count = 0;

  for( int i = 0; i < 10; i++ ){
    n[i] = 0;
  }

 while( cin >> train ){
   

   if( train != 0 ){
     ++count;
     n[count] = train;
   }else if( train == 0 ){
     for( int j = 10; j >= 0; j-- ){
       if( n[j] != 0 ){
	 cout << n[j] << endl;
	 n[j] = 0;
	 break;
       }
     }
   }



  
  
 }
 
  
  


  return 0;
}

C++: 
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)

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

C++: 
#include <stdio.h>

int train(int array[], int a)
{
	int i;
	for(i=0; i<10; i++)
	{
		if(array[i]==0)
		{
			if(a)
			{
				array[i]=a;
				return 0;
			}
			
			if(i>0 && a==0)
			{
				printf("%d\n", array[i-1]);
				array[i-1]=0;
				return 0;
			}
			return 0;
		}
	}
	return 0;
}
	

int main (void)
{
	int a, trains[10], i;
	
	for(i=0; i<10; i++)
	{
		trains[i]=0;
	}
	
	while(scanf("%d", &a)!=EOF)
	{
		train(trains, a);
	}
	
	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()),std::cout<<i.top()<<std::endl,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<cstdio>

int main(){
	int g[10];
	int i = 0;
	int t;
	while(scanf("%d", &t)){
		if(t){
			g[i] = t;
			i++;
		}else{
			i--;
			printf("%d\n", g[i]);
		}
	}
	return 0;
}

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

int main(){
	int car[10],t=0,n;
	while(cin>>n){
		if(n==0){
			cout<<car[--t]<<'\n';
		}
		else{
			car[t++]=n;
		}
	}
	return 0;
}