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>
using namespace std;

int main(){
  int stack[10];
  int *head;
  int car_num;

  head=stack;
  while(cin>>car_num){
    if(car_num>0){
      *head=car_num;
      head++;
    }
    else {
      printf("%d\n", *head);
      head--;
    }
  }

  return 0;
}

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

using namespace std;

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

C++: #include <iostream>

using namespace std;

typedef struct Stack {
        int array[100];
        int top;

        Stack()
                :top(0)
        {
                for (int i = 0; i < 100; i++) {
                        array[i] = 0;
                }
        }
} Stack;

int main()
{
        Stack stack;
        int car;

        while (cin >> car) {
                if (car) {
                        stack.array[stack.top++] = car;
                } else {
                        cout << stack.array[--stack.top] << endl;
                        stack.array[stack.top] = 0;
                }
        }

        return 0;
}

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

using namespace std;

int main(){
    int n;
    stack <int> inp;

    while(std::cin >> n){
        if(n != 0){
            inp.push(n);
        } else {
            std::cout << inp.top() << std::endl;
            inp.pop();
        }
    }
}

C++: #include<stdio.h>

int	i	=	0,	result;
int	train[100];
int outtrain[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,	cnt	=	0;
	outtrain[100]	=	0;
	while(1){
		scanf("%d",	&k);
		push(k);
		if(k	==	0){
			pop(train);
			outtrain[cnt]	=	result;
			cnt++;
			i	-=	2;
		}
		if(i	==	0)break;
	}
	for(k	=	0;	k	<=	cnt;	k++){
		if(outtrain[k]	!=	0)printf("%d\n",	outtrain[k]);
	}
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <iomanip>
using namespace std;
int main(){
  int in[10]={0},out[10]={0},i=0,o=0,n;
  while(cin>>n){
    if(!n)out[o++]=in[--i],in[i]=0;
    else{in[i++]=n;}
    if(!i&&o>0)break;
  }
  for(int j=0;j<o;j++)
    cout<<out[j]<<endl;
  return 0;
}

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

vector<int> car,ans;

int main()
{
	int n;
	while(scanf("%d",&n) != EOF) {
		if(n != 0) { car.push_back(n); }
		else {
			ans.push_back(car.back());
			car.pop_back();
		}
		if(car.empty()) { break; }
	}
	int Size = ans.size();
	for(int i=0;i<Size;++i) printf("%d\n",ans[i]);
	return 0;
}

C++: #include<stdio.h>

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

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

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

C++: #include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp= 0;

void pop(){
 sp--;
}

void push(int v){
 data[sp] = v;
 sp++;
}

int main(){
 int v;
 while(scanf("%d", &v) != EOF){
  if(v != 0){
    push(v);
  }
  if(v == 0){
   printf("%d\n", top());
   pop();
  }
 }
 return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> stk;
  int x;
  while(cin>>x){
    if(x) stk.push(x);
    else{
      cout<<stk.top()<<endl;
      stk.pop();
    }
  }
  return 0;
}

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

int main() {
  int i;
  int cnt = 0;
  std::vector<int> vec;
  while(cnt != 40) {
    scanf("%d", &i);
    if(i == 0){
      printf("%d\n", vec.back());
      vec.pop_back();
    }else{
      vec.push_back(i);
    }
    cnt++;
  }
  return 0;
}

C++: #include<iostream>
int main(){int a,c=0,s[12];while(std::cin>>a){if(a!=0)s[c++]=a;else std::cout<<s[--c]<<"\n"}return 0;}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    stack<int> sk;
    int a;
    while (~scanf("%d", &a)){
        if (a == 0){
            cout << sk.top() << endl;
            sk.pop();
        }else{
            sk.push(a);
        }
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

	int i, j=0, n, a[10], b[10];

	for(i=0; i<10; i++) {
		b[i]=0;
	}

	for(i=0; i<10; i++) {
		cin >> n;
		if(n==0) {
			b[j]=a[i-1];
			j++;
			i--;
			a[i]=n;
			if(i==0)
				break;
			i--;
			continue;
		}
		a[i]=n;
	}

	for(i=0; b[i]!=0; i++) {
		cout << b[i] << endl;
	}

	return 0;

}

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

int main(void)
{
	int n;
	stack<int> in;
	queue<int> out;

	while(cin >> n)
	{
		if(n == 0)
		{
			out.push(in.top());
			in.pop();
		}
		else
			in.push(n);
	}

	while(!out.empty())
	{
		cout << out.front() << endl;
		out.pop(); 
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int top,s[10];
void push(int x){
    s[++top]=x;
}
void pop(){
    top--;
    cout<<s[top+1]<<endl;
}
int main(){
    int num;
    while(1){
        cin>>num;
        if(num==0)
            pop();
        else push(num);
    }
    return 0;
}

C++: #include <stdio.h>

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

  return 0;
}