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 <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[250][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[220] = {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 <iostream>
#include <stack>

using namespace std;

int main(void){
	int n;
	stack<int> st;

	while(cin >> n){
		if(n != 0){
			st.push(n);
		}else{
			cout << st.top() << endl;
			st.pop();
		}
		//if(st.empty() == true) break;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<stack>
using namespace std;
int main(){
    int tra,ans[20];
    stack<int> s;
    for(int i=0;i<20;i++){
        cin>>tra;
        if(tra==0){
            cout<<s.top()<<endl;
            s.pop();
        }else{
            s.push(tra);
        }
    }
}

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

using namespace std;
int num;
stack<int> s;

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

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

#define MAX 256

int main(void){
	
	int i=0,j=0,x;
	int a[MAX];
	int ans[MAX];
	while(cin>>x){
		if(x==0){
			ans[j]=a[i-1];
			j++;
			i--;
		}else{
			ans[i]=x;
			i++;
		}
		
		
	}
	
	for(int i=0;i<j;i++){
		cout<<ans[i]<<endl;
	}
	
}

C++: #include<iostream>

using namespace std;

int main() {
	int train[200000] = { 0 }, junban[200000] = { 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 <iostream>

using namespace std;

int main(){
  short stack[10]={0};
  short *pstack=stack;
  int num;
  while(cin>>num){
    if(num){
      *pstack=num;
      pstack++;
    }else{
      pstack--;
      cout<<*pstack<<endl;
    }
    if(pstack==stack) break;
  }
}

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

int 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 car[10] = {}, b[100];
	int i = 0, cou = 0;
	while (cin >> b[i]) {
		if (b[i] != 0) {
			car[cou] = b[i];
			cou++;
		}
		if (b[i] == 0) {
			cout << car[cou - 1] << endl;
			cou--;
		}
		i++;
	}
    return 0;
}

C++: #include <stdio.h>

int main(void){
	int stack[10];
	int sp = -1;
	int n = 0;
	for(int i=0;i<10;++i){
		stack[i] = 0;
	}
	while(scanf("%d", &n) != EOF){
		if(n == 0){
			printf("%d\n", stack[sp]);
			sp--;
		}else{
			stack[++sp] = n;
		}
	}
	return 0;
}

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

int main()
{
	stack<int> R;
	int n;
	int car[10];
	int i = 0;
	
	while (cin >> n){
		if (n == 0){
			car[i] = R.top();
			R.pop();
			i++;
		}
		else {
			R.push(n);
		}
	}
	
	for (int j = 0; j < i; j++){
		cout << car[j] << endl;
	}
	
	return (0);
}

C++: import java.util.ArrayDeque;
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	ArrayDeque<Integer> stack = new ArrayDeque<Integer>();
	int n;
	while (scan.hasNext()) {
	    n = Integer.parseInt(scan.nextLine());
	    if (n == 0) {
		System.out.println(stack.pop());
	    } else {
		stack.push(n);
	    }
	}
    }
}

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

	int main(void){
		int train[100];
		int count = 0;
		int n;
		while(cin >> n){
			if(n > 0){
				train[count] = n;
				count++;
			}else if(n == 0){
				count--;
				cout << train[count] << endl;
			}
		}
		return 0;

	}

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

using namespace std;

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

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

using namespace std;
long long int num;
stack<int> s;

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

C++: #include <stack>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	stack<int> a;
	vector<int> o;
	int s=1,d;
	
	cin>>d;
	a.push(d);
	
	while(s!=0){
		cin>>d;
		if(d!=0) {
			a.push(d);
			s++;
		}
			else {
				s--;
				o.push_back(a.top());
				a.pop();
			}
	}
	for(int i=0;i<o.size();i++) {
		cout<<o[i]<<endl;
	}
}

C++: #include<iostream>
using namespace std;
#define N 11
int push();
int pop();
 int top=0;
  int buffer[N];
  int num;
  int out[N];
  int status;


int main(void){
 
  while(1){
    
    status = scanf("%d", &num);
    if(status == EOF)break;
    if(num != 0)push();
    else if(num == 0){
      cout << pop() << endl;
    }
  }
  
  
  return 0;
}

int push(){
  
  top++;
  buffer[top]=num;
}

int pop(){
  int x=buffer[top];
  top--;
  return x;
}

C++: #include <cstdio>
#include <vector>
int main(){
	int n;
	std::vector<int> v;
	while(scanf("%d\n", &n)+1){
		if(n){
			v.push_back(n);
		}else{
			printf("%d\n", v.back());
			v.pop_back();
		}
	}
	return 0;
}

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

int s[10],t;

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

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

int main(){
	std::stack<int> st;
	int num;
	
	do{
		std::cin >> num;
		if(num == 0){
			std::cout << st.top() << std::endl;
			st.pop();
		}else
			st.push(num);
	} while(!st.empty());
	
    return 0;
}

C++: #include<stdio.h>

int main(){
	int car[10];
	int a,c=0;
	while(~scanf("%d",&a)){
		if(a==0){
			printf("%d",car[c]);c--;
		}
		else {
			car[c]=a;
			c++;
		}
	}
}

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

int main()
{
	std::vector<int> train;

	std::vector<int> out;

	int n;

	while(std::cin >> n)
	{
		if(n!=0)
		{
			train.push_back(n);
		}
		else
		{
			out.push_back(train[train.size()-1]);

			train.pop_back();
		}
	}

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

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

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