Go: package main

import (
        "fmt"
)

func main() {
        var stk [101]int
        var c int
        pvt := 0
        for {
                _, err := fmt.Scanf("%d", &c)
                if err != nil {
                        break
                }
                if c > 0 {
                        stk[pvt] = c
                        pvt++
                } else {
                        pvt--
                        fmt.Printf("%d\n", stk[pvt])
                }
        }
}

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

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

using namespace std;



int main() {
	stack<int> s;
	
	int in;
	cin >> in;
	s.push(in);
	
	while (!s.empty()) {
		cin >> in;
		if (in==0) {
			cout << s.top() << endl;
			s.pop();
		}
		else s.push(in);
	}
	
	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( scanf("%d", &n) != EOF ){
		
		if(n==0){
			i--;
			printf("%d\n" , a[i]);
		}else{
			a[i] = n;
			i++;
		}
		if(i==0) break;
	}
	
	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()),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<iostream>
using namespace std;
int main(){
	int now=-1;
	int n[10]={0};
	int in;
	for(;;){
		cin>>in;
		if(in==0){
			cout<<n[now];
			now--;
			if(now==-1)return 0;
		}
		else{
			n[now+1]=in;
			now++;
		}
	}
}