Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	n, err := strconv.Atoi(nextString())
	return n, err
}

func main() {
	scanner.Split(bufio.ScanWords)

	stack := []int{}
	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		if n == 0 { // pop
			fmt.Println(stack[len(stack)-1])
			stack = stack[0:(len(stack) - 1)]
		} else { // push
			stack = append(stack, n)
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int number,count1,count2,enter[10],leave[10],sum;
  
  count1=0;
  count2=0;
  for(int i=0;i<10;i++){
    cin >> number;
    if(number!=0){
      enter[count1]=number;
      count1++;}
    else if(number==0){
      count1--;
      leave[count2]=enter[count1];
      count2++;}
    if(count1+2<count2)break;
			}
  for(int i=0;i<count2;i++){
    cout << leave[i]<< endl;
  }
 
  return 0;
  }

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

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

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

int main(){
	//Switching queue
	std::deque<int> que;
	int tmp;
	
	while(std::cin >> tmp){
		if(tmp == 0){
			std::cout << que.back() << std::endl;
			que.pop_back();
		}
		else que.push_back(tmp);
	}
		return 0;
	}

C++: #include<iostream>

using namespace std;

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

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