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

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

using namespace std;

int main() {
	int data[10];
	stack<int> line;
	vector<int> top;
	int i = 0;

	while (cin >> data[i]) {
		++i;
	}

	for (auto i : data) {
		if (i == 0) {
			top.push_back(line.top());
			line.pop();
		}
		else {
			line.push(i);
		}
	}

	for (auto t : top) {
		cout << t << endl;
	}

	return 0;
}

C++: #include <iostream>

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

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