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

C++: #include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <istream>
#include <iomanip>
 
#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif


int main(int argc, char **argv){
	std::vector<int> stack;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

#if INPUT_FROM_FILE
	while(std::getline(ifs, buf)){
#else
	while(std::getline(std::cin, buf)){
#endif
		int n = std::stoi(buf);

		if(n != 0){
			stack.push_back(n);
		}
		else{
			std::cout << stack.back() << std::endl;
			stack.pop_back();
		}
	}
	return 0;
}

C++: #include <stdio.h>

int train[10];
int sp = 0;

int empty() {
  return sp <= 0;
}

int size() {
  return sp;
}

int top() {
  return train[sp-1];
}

void pop() {
  sp--;
}

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

int main(){
  int num;
  while(1){
    scanf("%d", &num);
    if(num == 0){
      printf("%d\n", top());
      pop();
    }else{
      push(num);
    }
    if(size() == 0) break;
  }
  return 0;
}

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

int main(){
	vector<int> car, exit;
	int n;
	
	while( cin >> n ){
		
		if(n==0){
			exit.push_back( car.back());
			car.pop_back();
		}else{
			car.push_back(n);
		}
		if(car.size()==0) break;
	}
	vector<int>::iterator it = exit.begin();

	while( it != exit.end() ){
		cout << *it << endl;
		++it;
	}
	return 0;
}

C++: #include<cstdio>
#include<stack>
using namespace std;
int main() {
	int n;
	stack<int> S;
	while(~scanf("%d",&n)) {
		if(n)
			S.push(n);
		else {
			printf("%d\n",S.top());
			S.pop();
		}
	}
	return 0;
}

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

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

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

int main()
{
	vector<int> train;
	for (int i = 0, n; i < 10 && cin >> n;) {
		switch (n) {
		case 0:
			cout << train.back() << endl;
			train.pop_back();
			i++;
			break;
		default:
			train.push_back(n);
		}
	}
	return 0;
}

C++: #include<stdio.h>
int i=0,j=0;
int cars[19];

int main(){
    while(1)
    {

        if(scanf("%d",&cars[i])==-1)
        {
            break;
        }
        if(cars[i]==0){
            printf("%d\n",cars[i-1]);
            i--;
        }
        else
        {
            i++;
        }
    }
    return 0;
}

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

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

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(i=l;i<n;i++)
using namespace std;

int main(){
	int data[15]={},i=0,n;

	while(1){
		cin>>n;
		if(n!=0){
			data[i]=n;
			i++;
		}else if(n==0){
			cout<<data[i-1]<<endl;
			i--;
		}
	}
}

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)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}
	
	cout << outlist[i] << '\n';
	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<stack>
#include<algorithm>
using namespace std;
int main(void){
    int j=0;
	int k;
	int b[1000]={0};
	stack<int> a;
	a.push(-1);
	for(int i=0;;i++){
        if(i>=1&&a.top()==-1)break;
        cin>>k;

        if(k==0){
            b[j]=a.top();
            j++;
            a.pop();
        }
        else a.push(k);
	}
	for(int i=0;i<j;i++){
        cout<<b[i]<<endl;
	}


	return 0;
}