Go: package main

import "fmt"

func main() {
	stack := []int{}
	for {
		var a int
		i, _ := fmt.Scan(&a)
		if i == 0 {
			break
		}
		if a == 0 {
			fmt.Println(stack[len(stack)-1])
			stack = stack[:len(stack)-1]
			continue
		}
		stack = append(stack, a)
	}
}

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

int main(void){
  stack<int> car;
  int num,res[10000],cnt=0,cnt1=0;

  while( cin >> num ){

    if( num != 0 ) car.push(num);
    else{
      res[cnt] = car.top();
      car.pop();
      cnt++;
      cnt1++;
    }
  }

  cnt = 0;

  while(cnt1){

    cout << res[cnt] << endl; 
    cnt++;
    cnt1--;

  }

  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( 1 ){
		scanf("%d", &n);
		if(n==0){
			i--;
			printf("%d\n" , a[i]);
		}else{
			a[i] = n;
			i++;
		}
		if(i==0) break;
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <stack>
using namespace std;
int main(){
  int n;
  stack<int> in,out;
  while(cin>>n){
    if(!n)out.push(in.top()),in.pop(),cout<<out.top()<<endl;
    else{in.push(n);}
    if(in.empty()&&!out.empty())return 0;
  }
}

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

int main(void)
{
	int car[20] = {0};
	int in = 0;

	while(car[0] != -1) {
		int n;
		cin >> n;
		car[in] = n;

		if(n == 0) {
			for(int i = in - 1; i >= 0; i--) {
				if(car[i] > 0) {
					cout << car[i] << endl;
					car[i] = -1;
					break;
				}
			}
		}

		in++;
	}
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(void){
    // Here your code !
    stack<int> s;
   for(int d;cin>>d;){
    
       if(d==0){
           cout<<s.top()<<endl;
           s.pop();}
       else{
           s.push(d);
       }
}
}

C++: #include<cstdio>
#include<cmath>
 
//#include<iostream>
using namespace std;
 
int main(){
int i=0, j, ar[11];

	while( scanf("%d" , &j)!= EOF){
		if(j!=0)	ar[++i]=j;
		else 		printf("%d\n",ar[i--]);
	}

    return 0;
}

C++: #include<stdio.h>

int main(){
	int car[11],i=0,n;
	do{
		scanf("%d",&n);
		if(n){
			car[i]=n;
			i++;
		}else{
			i--;
			printf("%d\n",car[i]);
			
		}
	}while(1);
}

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

int main(){
  stack<int> car;
  int n,cou=0,i=0,ans[1111];
  while(cin >> n){
    if(n == 0){
      cout << car.top() << endl;
      car.pop();
    }
    else{
      car.push(n);
    }
  }
}

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;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  stack<int> s;
  int n;
  while(cin>>n){
    if(n!=0)s.push(n);
    else{
      cout <<s.top() <<endl;s.pop();
    }
  }
  return 0;
}

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

int main()
{
  stack<int> trains;
  int i;
  for (;;)
  {
    cin >> i;
    if (i != 0) trains.push(i);
    else
    {
      if (trains.empty()) break;
      cout << trains.top() << endl;
      trains.pop();
    }
  }
  return 0;
}

C++: #include<stdio.h>
int main(){
	int a,b,c,d,train[100];
	b=0;
	c=0;
	
	int g;
	int cont = 0;
	
	for(a=0;a<1000;a++){
		scanf("%d",&g);
		
		if(g != 0){
			train[cont] = g;
			cont++;
		}
		else{
			printf("%d\n",train[cont-1]);
			cont--;
		}
		
		if(cont == 0){
			break;
		}
		/*
		if(train[a]==0){
			c++;
		}else{
			b++;
		}
		if(b==c){
		break;
		} 
		*/
	}
}

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

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

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

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

int main(){
	std::stack<int> in;
	std::queue<int> out;
	int num;
	
	while(std::cin >> num){
		if(num == 0){
			out.push(in.top());
			in.pop();
		}else
			in.push(num);
		
		//output
		if(in.empty()){
			while(!out.empty()){
				std::cout << out.front() << std::endl;
				out.pop();
			}
		}
	}
	
    return 0;
}

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

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

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

int main(){
	int a[100];
	int i = 0;

	for (int i = 0; i < 100; i++){
		a[i] = 0;
	}

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


	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く 
　　提出する問題を間違えない */
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
int main(){
  stack<int> train;
  int a;
  while(1){
    cin >> a;
    if(a){
      train.push(a);
    }else{
      if(cin.eof())break;
      cout << train.top() << endl;
      train.pop();
    }
  }
}

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

using namespace std;

int main()
{
    vector<int> Car;
    int Size = 0;
    int number;
    vector<int> Order;

    while(cin >> number)
    {

            if(number != 0)
            {
                Car.push_back(number);
            }
            else if(number == 0)
            {

                Order.push_back(Car[(Car.size())-1]);
                Car.pop_back();

            }




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

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 <iostream>
#include <stack>

using namespace std;

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

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>
#include <stack>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int in;
  stack<int> s;

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

  return 0;
}

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