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

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

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

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

int main(void){
	int n;
	vector<int> car;

	cin >> n;
	car.push_back(n);

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

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

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

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

int main() {
  stack<int> sta;
  
  while(1){
  
    int temp;
    cin >> temp;
    
    if (temp==0){
      if (sta.empty()){
	cout << sta.top() <<endl;
	sta.pop();
	if (sta.empty()) break;
      }
    }else{
      sta.push(temp);
    }
  }
    
  return 0;
  
}

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

int main(){
  stack<int> st;
  int a;
  while(cin>>a){
    if(a)st.push(a);
    else {printf("%d\n",st.top());
      st.pop();
    }
}

   }
  return 0;
}

C++: //Switching Railroad cars

#include <iostream>
#include <stack>
using namespace std;

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

C++: #include <iostream>
#include <vector>
using namespace std;
int main(void)
{
    vector<int> t;
    int a;
    do
    {
        cin >> a;
        if (a != 0)
        {
            t.push_back(a);
        }
        else if (a == 0)
        {
            cout << t.back() << endl;
            t.pop_back();
        }
    } while (!t.empty());
}

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

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

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

using namespace std;

int main() {
  int n;
  vector<int> train;

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

C++: #include <iostream>
#include<iomanip>
#include <vector>
#include <algorithm>
#include<math.h>
using namespace std;

int main(){
	int n;
	vector <int> g;
	while(true){
		cin>>n;
		if(n!=0){
			g.push_back(n);
		}else{
			n=g.back();
			g.pop_back();
			cout<<n<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>

int main(){
  int i,a;
  int train[1000];

  i = -1;

  while(std::cin >> a){
    if(a == 0){
      std::cout << train[i] << std::endl;
      --i;
      continue;
    }
    ++i;
    train[i] = a;
  }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <ctime>
#include <cmath>
#include <cassert>
#include <limits>
#include <functional>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(int)(n);++(i))

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

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

int main()
{
	int car[10],order[100],i,j,k=0;
	
	for(i=0; i<10; i++){car[i]=0;}
	i=0;
	while((scanf("%d",&order[i]))!=EOF){i++;}
	for(j=0; j<i; j++){
		if(order[j]!=0){
			car[k]=order[j];
			k++;
		}else{
			k--;
			cout << car[k] << endl;
			car[k]=0;
		}
	}
	
	
	return 0;
}

C++: //
//  main.cpp
//  BT
//
//  Created by h3037175 on 2017/07/27.
//  Copyright ?? 2017??´ h3037175. All rights reserved.
//

#include <iostream>
#include <stack>
using namespace std;
int main() {
    stack<int> st;int a;
    while(cin>>a){
        if(a==0){
            cout<<st.top()<<endl;
            st.pop();
        }
        else{
        st.push(a);
        }
    }
        return 0;
}

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

using namespace std;

int main(){

  vector<int> V;
  int in;
  while(cin >> in){
    if(in != 0) V.push_back(in);
    else{
      cout <<  V.back() << endl;
      V.pop_back();
    }
  }
  return 0;
}

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

int main()
{
	int N;
	stack<int> train;
	queue<int> leave;
	while (cin >> N) {
		if (N == 0) {
			leave.push(train.top());
			train.pop();
		}
		else {
			train.push(N);
		}
	}
	for (; leave.empty() == 0;) {
		cout << leave.front() << endl;
		leave.pop();
	}
	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();
      if(sp = 0) break;
    }else{
      push(num);
    }
  }
  return 0;
}