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 <cstdio>
#include <stack>
#include <vector>
using namespace std;

int main(void) {
    stack<int> unforwardable;
    vector<int> output;
    bool update = false;
    while(!update || !unforwardable.empty()) {
        update = true;
        int car; cin >> car;
        if(car == 0) {
            output.push_back(unforwardable.top());
            unforwardable.pop();
        } else {
            unforwardable.push(car);
        }
    }
    vector<int>::iterator ite;
    for(ite = output.begin(); ite != output.end(); ite++) {
        cout << *ite << endl;
    }
    return(0);
}

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

using namespace std;

int main()
{
	stack<int> st;

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

		st.push(n);
	}

	return 0;
}

C++: #include<stdio.h>

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

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

C++: #include <cstdio>

using namespace std;

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

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

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

}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;
int main(){
	stack<int> train;
	int n;
	while(cin>>n){
		if(n!=0){
			train.push(n);
		}else{
			cout<<train.top()<<endl;
			train.pop();
		}
	}
	return 0;
}

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

int main(){
	int in[10],out[10];
	int in_num=0;
	int out_num=0;
	int n;
	while(cin >>n){
		if(n == 0){
			in_num--;
			out[out_num] = in[in_num];
			out_num++;
		}
		else {
			in[in_num] = n;
			in_num++;
		}
	}
	for(int i=0;i<out_num;i++)
		cout <<out[i]<<endl;
}

C++: #include<cstdio>
#include<stack>
using namespace std;
int main(){
  stack<int> s;
  do{
    int num;scanf("%d",&num);
    if(num){
      s.push(num);
    }else{
      printf("%d\n",s.top());
      s.pop();
    }
  }while(!s.empty());
}

C++: #include<iostream>

using namespace std;

int main() {
	int train[10] = { 0 }, junban[10] = { 0 }, a = 0, n, i;
	while (cin >> n) {
		if (n == 0) {
			for (i = 0; train[i] > 0; i++) {}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; train[i] > 0; i++) {}
			train[i] = n;
		}
	}
	for (i = 0; junban[i] > 0; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}

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

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair
typedef long long LL;
#define EPS (1e-6)
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef pair<double,double> P;

bool isCross(P p1, P p2, P p3, P p4){
  double c = ((p1.first - p2.first) * (p3.second - p1.second) + (p1.second - p2.second) * (p1.first - p3.first)) * 
    ((p1.first - p2.first) * (p4.second - p1.second) + (p1.second - p2.second) * (p1.first - p4.first));
  if(c<=0.0)
    return true;
  return false;
}

int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(3);

  int INF = 1000000;

  stack<int> rail;

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

    }
  }
  


  return 0;
}

C++: #include <stdio.h>
int main(){
    int stay[10];
    int out[100];
    int i=0, k=0, j=0,n;
    while(scanf("%d",&n) != EOF){
        if(n==0){
            out[k]=stay[i-1];
            k++;
            //stay[i]=stay[i-2];
            i--;
        }else{
            stay[i]=n;
            i++;
        }
    }
    for(j=0;j<k;j++){
        printf("%d?\n",out[j]);
    }
    return 0;
}

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

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

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define llong long long

int main() {
  stack<int> st;
  int in;
  while(scanf("%d",&in) != EOF) {
    if(in == 0) {
      printf("%d\n",st.top());
      st.pop();
    }
    else {
      st.push(in);
    }
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
        int *x; 
        int _x[10];
        x = _x; 
        int in = 0;
        while(cin >> in){
                if(!in){
                        cout << *(x-1) << endl;
                        x--;
                }else{
                        *x = in; 
                        x++;
                }   
        }   
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
void pop(int *i,int *a){
	cout<<*a<<endl;
	*i-=1;
	*a=0;
}
void push(int *i,int *a,int n){
	*a=n;
	*i+=1;
}
int main(){
	int a[100],i,n,j,k,p;

	for(i=0;i<100;i++){
		a[i]=0;
	}
	i=0;
	while(cin>>n){
		if(n==0){
			pop(&i,&a[i-1]);
		}else{
			push(&i,&a[i],n);
		}
	}
    return 0;
}

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

using namespace std;

int main(){

    vector<int> v;
    int n;

    while (cin >> n)
    {
        if (n == 0){
            cout << v.back() << endl;
            v.pop_back();
        }
        else
        {
            v.push_back(n);
        }
    } 

    return 0;
}

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

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

int main()
{
	stack<int> car;
	vector<int> outlist;

	while( !car.empty() || outlist.empty() )
	{
		int carnum;
		cin >> carnum;
		if(carnum!=0)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}

	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

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

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