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 <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl



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

C++: #include<stdio.h>

int	i	=	0,	result;
int	train[100];

void	push(int	k){
	train[i]	=	k;
	i++;
}

void	pop(int train[]){
	int	a,	check	=	0;
	for(a	=	i	-	1;	a	>=	0;	a--){
		if(train[a]	!=	0){
			result	=	train[a];
			train[a]	=	0;
			check	+=	1;
		}
		if(check	!=	0)break;
	}
}


int	main(){
	int	k;
	while(1){
		scanf("%d",	&k);
		push(k);
		if(k	==	0){
			pop(train);
			i	-=	2;
			printf("%d\n",	result);
		}
		if(i	==	0)break;
	}
}

C++: #include <stdio.h>

#include <string.h>

#include <stack>

#include <iostream>


using namespace std;

int main(){
    
    int input;
    stack<int> train;
    for (;;) {
        scanf("%d",&input);
        if (input!=0)train.push(input);
        else {
            printf("%d",train.top());
            train.pop();
        }
    }
}
    //        if(strcmp(c,pu) == 0){
    //
    //            scanf("%s",&color);
    //
    //            st.push(color);
    //
    //        }
    //
    //        if(strcmp(c,po) == 0){
    //
    //            cout<<st.top()<<endl;
    //
    //            st.pop();
    //
    //        }
    //
    //        if(strcmp(c,qu) == 0){
    //
    //            return 0;
    //
    //        }
    //
    //    }
    
    //}

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


int main(){

  int train , num[20] , k = 0 , count[20];

 for( int i = 0; i < 20; i++ ){
   count[i] = 0;
    num[i] = 0;
 }

 while( cin >> train ){
   
   ++k;
   num[k] = train;
    if( train == 0 ){
      for( int j = 20; j >= 0; j-- ){
	if( num[j] != 0 ){
	count[k] = num[j];
	num[j] = 0;
	break;
	}
      }
    }
  }
 
  
  for( int k = 0; k < 20; k++ ){
    if( count[k] != 0 ) cout  << count[k] << endl; 

  }


  return 0;
}

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

int main(void){
     int n[100];
     int i=0;
     int d;
     do{
	  cin >> d;
	  if(d == 0){
	       cout << n[i-1] << endl;
	       i = i-1;
	  }else{
	       n[i] = d;
	       i = i+1;
	  }
//	  cout << endl;
//	  for(int i=0;i<10;i++){
//	       cout << n[i-1] << endl;
//	  }
//	  cout << endl;
     }while(i!=0);

     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();
		}
		if(stack.empty()){
			break;
		}
	}
	return 0;
}

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

C++: #include <stdio.h>

int main()
{
int p[11]={};
int x,i;
i=0;x=0;
while(scanf("%d",&x)!=EOF)
{
if(x%10>0){p[i]=x;i++;}
else{i--;printf("%d\n",p[i]);}

}
return 0;
}

C++: //Switching Railroad Cars

//vñF0ªüÍ³ê½çStack©çpopµÄ»êðoÍµëA»êÈOÍpushµÆ¯
//üÍª³µ¢±ÆÍÛá³êÄ¢é@¿ÈÝÉpush³êéàÌÍ1`10çµ¢

//ÅÍX^bNÍóÅ é@ÉX^bNªóÉÈéÜÅ±¯æ

#include<iostream>
#include<stack>
using namespace std;

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

C++: #include<iostream>
using namespace std;
int main(){
  int number,count1,count2,enter[10],leave[10],sum;
  sum=0;
  count1=0;
  count2=0;
  while(1){
    cin >> number;
    if(number!=0){sum++;
      enter[count1]=number;
      count1++;}
    else if(number==0){
      count1--;
      leave[count2]=enter[count1];
      count2++;}
    if(sum-1<count2)break;
			}
  for(int i=0;i<count2;i++){
    cout << leave[i]<< endl;
  }
 
  return 0;
  }

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

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num==0) pop();
		else push(num);
	}

    return 0;
}

C++: {
stack<int>a;
int b;
scanf("%d",&b);
a.push(b);
while(cin>>b){
	if(b)a.push(b);
	else {printf("%d\n",a.top());a.pop();}
}
}

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

C++: #include<stdio.h>
const int SIZE=100;
int data[SIZE];
int sp=0;
int size(){
  return sp;
}
int empty(){
  return sp<=0;
}
int top(){
  return data[sp-1];
}
void pop(){
  sp--;
}
void push(int v){
  data[sp]=v;
  sp++;
}
int main(){
  int n,k;
  while(1){
    scanf("%d",&n);
    if(n==EOF)break;
    if(n==0){
      printf("%d\n",top());
      pop();
    }else{
      push(n);
    }
  }
  return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  stack<int> chu;
  int i=0;
  int input;
  int hairetu[10];
  cin>>input;
  chu.push(input);
  while(!chu.empty()){
    cin>>input;
    if(input!=0){
      chu.push(input);
    }else{
      hairetu[i]=chu.top();
      chu.pop();
      i++;
    }
  }
  for(int j=0;j<=i-1;j++){
    cout<<hairetu[j]<<endl;
  }
  
}

C++: q=[];require("fs").readFileSync("/dev/stdin","utf8").trim().split('\n').map(function(i){i?q.push(i):console.log(q.pop())})

C++: #include <iostream>

using namespace std;

int main(){
  short stack[10]={0};
  short *pstack=stack;
  while(1){
    int num;
    cin>>num;
    if(num){
      *pstack=num;
      pstack++;
    }else{
      pstack--;
      cout<<*pstack<<endl;
    }
  }
}

C++: #include<stack>
#include<deque>
#include<iostream>
using namespace std;
int main(){
	int m,n;
	deque<int>deq;
 	while(1){
	    cin>>n;
	    if(cin.eof()) break;
	    if(n!=0) deq.push_back(n);
	    else {  
                     if(deq.empty()) { continue;}
                     else {     cout<<deq[(int)deq.size()-1]<<endl;
				deq.pop_back();}
            }
	}
        return 0;
}

C++: #include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
int main(){
    stack <int> st;
    int n;
    while(cin >> n){
        if(n)
            st.push(n);
        else{
            cout << st.top() << endl;
            st.pop();
        }
    }
}