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

using namespace std;

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

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

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

using namespace std;

int main(){
	vector<int> RailRoad, out;
	int buf;

	// 入力の終わりまで読み込み
	while(cin >> buf){
		if(buf == 0){
			buf = RailRoad[((int)RailRoad.size() - 1)];
			out.push_back(buf);
			RailRoad.pop_back();
		}else{
			RailRoad.push_back(buf);
		}
	}

	// イテレータの初期化
	for(vector<int>::iterator it = out.begin();it != out.end();++it){
		cout << *it << endl;
	}

	return 0;
}

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

int main(){
    int n;
    std::stack<int> st;
    while(1){
        std::cin >> n;
        if(n == 0){
            std::cout << st.top() << std::endl;
            st.pop();
        }
        else
        {
            st.push(n);
        }
        if(std::cin.eof())
            break;
    }
}

C++: #include <stdio.h>
#include <string.h>

int st[10];

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

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

int main(){
	int out[10], car[10];
	int x, k = 0, i = 0;
	while(cin >> x){
		if(x != 0){
			car[i] = x;
		}
		else{
			out[k] = car[i-1];
			i = i-2;
			k++;
		}
		i++;
	}
	for(int j = 0; j < k; j++){
		cout << out[j] << endl;
	}
}

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

using namespace std;

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

  return 0;
}

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

using namespace std;

int main(){
  vector<int> train;
  vector<int> queue;
  int num;

  while(cin >> num){
    if(num != 0){
      train.push_back(num);
    }else{
      queue.push_back(train.back());
      train.pop_back();
    }
  }

  for(int i=0; i<queue.size(); i++){
    cout << queue[i] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>

using namespace std;

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

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

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

int main(){
	int out[100], car[100];
	int x, k = 0, i = 0;
	while(cin >> x){
		if(x != 0){
			car[i] = x;
		}
		else{
			out[k] = car[i-1];
			i = i-2;
			k++;
		}
		i++;
	}
	for(int j = 0; j < k; j++){
		cout << out[j] << endl;
	}
}

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

int main()
{
	int train[100000]={};
	long int i=0;
	for(int j=0;j<20;j++){
		cin>>train[i];
		if(train[i]==0){
			i--;
			cout<<train[i]<<endl;
		}else{
			i++;
		}
	}
}

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

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

C++: #include <stdio.h>

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

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

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

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;
}