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++:  /*
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.

We can simulate the movement (comings and goings) of the cars as follow:

An entry of a car is represented by its number.
An exit of a car is represented by 0
For example, a sequence

1 6 0 8 10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.

Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
 */
 
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	vector<int> cars, ans;
	int temp, i=0, m;
	while (cin >> temp) {
		if (temp != 0) {
			cars[i] = temp;
			i++;
		} else {
			ans.push_back(cars.at(i-1));
			i--;
		}
	}
	for (int j=0; j<ans.size(); j++)
		cout << ans[j] << endl;
	return 0;
}

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

using namespace std;
int main()
{
	stack<int> st;
	int i, n;
	
	while(cin >> n)
	{
		if(n != 0)
		{
			st.push(n);
		}
		else
		{
			i = st.top();
			cout << i << endl;
			st.pop();
		}
	}
	
	return 0;
}

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

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

C++: #include<iostream>
#include<vector>
int main(){
	std::vector<int> car,ans;
	int a;
	//int h=0;
	bool f=false;
	//std::vector<int>::iterator it=car.begin();
	while(std::cin>>a){
		if(a!=0&&!f){
			car.push_back(a);
			f=true;
		}else if(a!=0){
			//h++;
			//++it;
			car.push_back(a);
		}else{
			//ans.push_back(car[h]);
			//ans.push_back(n);
			ans.push_back(car.back());
			//it--;
			car.pop_back();
			//h--;
		}
	}
	for(int i=0;i<ans.size();i++){
		std::cout<<ans[i]<<std::endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>

#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)

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

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

	return 0;
}

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

using namespace std;

int main(){
  int n;
  vector<int> Stop, Free;

  while(cin >> n){
    if(n == 0){
      n = Stop[Stop.size()-1];
      Stop.pop_back();
      Free.push_back(n);
    }else{
      Stop.push_back(n);
    }
  }

  for(vector<int>::size_type i=0; i != Free.size(); ++i){
    cout << Free[i] << endl;
  }

  return 0;
}

C++: #include<stdio.h>
int main(void)
{
    int train[10]={0},n,count=0,outTrain[10],trainCount=0;
    while(scanf("%d",&n)!=EOF){
        if(n){
            for(int i=count ; i!=0 ; i--){
                train[i]=train[i-1];
            }
            train[0]=n;
            count++;
        }
        else{
            outTrain[trainCount]=train[0];
            for(int i=0 ; i<count ; i++){
                train[i]=train[i+1];
            }
            train[count]=0;
            count--;
            trainCount++;
        }
    }
    for(int i=0 ; i<trainCount ; i++){
        printf("%d\n",outTrain[i]);
    }
    return 0;
}

C++: #include <stdio.h>

int train(int array[], int a)
{
	int i;
	for(i=0; i<10; i++)
	{
		if(array[i]==0)
		{
			if(a)
			{
				array[i]=a;
				return 0;
			}
			
			if(i>0 && a==0)
			{
				printf("%d\n", array[i-1]);
				array[i-1]=0;
				return 0;
			}
		}
	}
}
	

int main (void)
{
	int a, trains[10], i;
	
	for(i=0; i<10; i++)
	{
		trains[i]=0;
	}
	
	while(scanf("%d", &a)!=EOF)
	{
		train(trains, a);
	}
	
	return 0;
}

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

int main()
{
	vector<int> S;

	int c;
	while(cin>>c)
	{
		if(c==0)
			cout<<S.back()<<endl,
			S.pop_back();
		else
			S.push_back(c);
	}
	return 0;
}

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

int main(){
	int a[100], i = 0;
	while (true){
		cin >> a[i];
		if (cin.eof()) { break; }
		if (a[i] == 0 ){
			cout << a[i - 1] << endl;
			i--;
		}
		else { i++; }
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int car;
	int a[11];
	int i,s;
	i=0;
	while(scanf("%d",&car)!=EOF){
		if(car!=0){
			a[i]=car;
			i++;
		}
		else {
			i--;
			printf("%d\n",a[i]);
		}
	}
	return 0;
}

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

int main() {
	int in;
	vector <int> a;
	while (cin >> in) {
		if (in == 0) {
			cout << a.back();
			a.pop_back();
			/*if (a.size() == 0)
				break;
			else*/
				cout << endl;
		}
		else
			a.push_back(in);
	}
	return 0;
}

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

stack<int> sta;

int main(void)
{
  int a;
  while(scanf("%d", &a)!=EOF){
    if(a)
      sta.push(a);
    else{
      cout<<sta.top()<<endl;
      sta.pop();
    }
  }
  return 0;

}

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

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

using namespace std;

int main() {
    stack<int> st;

    for(int n; cin >> n;) {
        if(n == 0) {
            cout << st.top() << endl;
            st.pop();
        }
        else {
            st.push(n);
        }
    }



    return 0;
}

C++: #include<stack>
#include<deque>
#include<iostream>
using namespace std;
int main(){
	int m,n;
	deque<int>deq;
 	while(1){
	    cin>>n;
	    if(n!=0) deq.push_back(n);
	    else {  
                     if(deq.empty()) { continue;}
                     else {     cout<<deq[(int)deq.size()-1]<<endl;
				deq.pop_back();}
            }
	}
        return 0;
}

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

int main() {
	
	int n , m[12] = {} ;
	
	while( cin >> n ){
		if( cin.eof() ) break ;
		if( n==0 ){
			for( int i=11 ; i>=0 ; i-- ){
				if( m[i] != 0 ){
					cout << m[i] << endl ;
					m[i] = 0 ;
					break ;
				}
			}
		}
		else {
			for( int i=0 ; i<12 ; i++ ){
				if( m[i] == 0 ){
					m[i] = n ;
					break ;
				}
			}
		}
	}
	
	return 0;
}

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

int main(){
    stack<int> st;

    int n;

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