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++: 
#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;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
using namespace std;

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

}

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

using namespace std;

int main(){
    int n;
    std::stack<int> st;
    while(scanf("%d", &n) != EOF){
        if(n == 0){
            cout << st.top() << endl;
            st.pop();
        }
        else
            st.push(n);
    }
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a[10],i=0,n;
	while(scanf("%d",&n)==1){
		if(n!=0){
			a[i]=n;
			i++;
		}
		else{
			i--;
			cout<<a[i]<<endl;
		}
	}
	return 0;
}

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

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

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

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<stack>
using namespace std;

stack <int> st;

void enter(int car) {
  st.push(car);
}

void exit() {
  cout << st.top() << endl;
  st.pop();
}

int main() {
  int car;
  while (cin >> car) {
    if (car == 0) {
      exit();
    } else {
      enter(car);
    }
  }
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
  vector<int> a;
  int n;
  while(cin >> n){
    if(n==0){
      cout<< a.back()<<endl;
      a.pop_back();//delete
    }else
      a.push_back(n);
  }
  return 0;
}

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

stack<int> st;
int main()
{
  int a;
  int train[1000];
 
  while(1)
    { cin >>a;
      if(a!=0)
	st.push(a);
      else 
	if (st.empty())
	  break;
	else{
	
	  cout <<st.top()<<"\n";
	  st.pop();}
      
    }
  
return 0;
}

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

using namespace std;

int main(){
  vector<int> rail;
  int rNum;
  while(cin >> rNum){//EOF de break
    if(rNum == 0){     
      cout << *rail.rbegin(); 
      rail.pop_back();
    }
    else  if(rNum <= 10 && rNum >= 0) rail.push_back(rNum);
  }  
  cout << endl;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
  vector<int> a;
  int n;
  while(cin >> n){
    if(n==0){
      cout<< a.back();
      a.pop_back();//delete
    }else
      a.push_back(n);
  }
  return 0;
}

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

int main()
{
	stack<int> stk;
	int n,out;

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

	return 0;
}

C++: #include <stdio.h>

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

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

int main(){
  int x;
  stack<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 <deque>
#include <algorithm>
using namespace std;


int main()
{
	int num;
	deque<int> train;
	while( cin >> num ) {
		if( num == 0 ) {	
			cout << train.back() <<endl;
			train.pop_back();
		}
		else {
			train.push_back( num );
		}
	
	}
	

	return 0;
}

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

int main(){
	int n,count = 0;
	stack<int> get;
	while(1){
		cin >> n;
		if(n==0){
			cout <<  get.top() << endl;
			get.pop();
			count -= 1;
		}
		else{
			get.push(n);
			count += 1;
		}
		if(count == 0) break;
	}
	return 0;
}

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

stack <int> st;

void enter(int car) {
  st.push(car);
}

void exit() {
  cout << st.top() << endl;
  st.pop();
}

int main() {
  int car;
  while (cin >> car) {
    if (car == 0) {
      exit();
    } else {
      enter(car);
    }
  }
}