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 <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	vector<int> cars(100000), ans;
	int temp, i=0, m;
	while (scanf("%d\n", &temp)) {
		if (temp != 0) {
			cars[i] = temp;
			i++;
		} else {
			ans.push_back(cars[i-1]);
			i--;
		}
	}
	for (int j=0; j<ans.size(); j++)
		cout << ans[j] << endl;
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>

using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    stack<int> st;
    queue<int> q;
    while (cin >> n)
    {
        if (n != 0)
        {
            st.push(n);
        }
        else
        {
            q.push(st.top());
            st.pop();
        }
    }
    while (q.size())
    {
        cout << q.front() << endl;
        q.pop();
    }
    return 0;
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

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

int main(){
    std::vector<int> in_train;
    std::vector<int> out_train;
    
    int a; //for input

    while(std::cin >> a){
        if(a == -1){
	    break;
	}else if(a > 0){
	    in_train.push_back(a);
	}else if(a == 0){
	    int e = in_train.back();
	    //std::cout << e << std::endl;
	    out_train.push_back(e);
	    in_train.pop_back();
	}
    }
    
    
    while(out_train.empty() != true){
        int e = out_train.front();
        std::cout << e << std::endl;
        out_train.erase(out_train.begin());
    }
    
    return 0;
}

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

int main(){
	std::stack<int> trains;

	do{
		int in;
		std::cin >> in;

		if(in == 0){
			std::cout << trains.top() << std::endl;
			trains.pop();
		}
		else
			trains.push(in);
	}while(!trains.empty());
	return 0;
}

C++: #include<stdio.h>

int main(){
	int car[11],i=0,n;
	while(1){
		if(scanf("%d",&n)==EOF)break;
		if(n){
			car[i]=n;
			i++;
		}else{
			i--;
			printf("%d\n",car[i]);
			
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
#include <stack>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

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

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

int main(){
	int a[100]={0};int n=0;
	while(cin>>a[n++]);n--;
	int b[10]={0};
	for(int i=0;i<n;i++)
	{
		if(a[i]==0)
		{
			cout<<b[0]<<endl;
			for(int j=0;j<10;j++)
			{
				b[j]=b[j+1];
			}
		}else
		{
			for(int j=9;j>0;j--)
			{
				b[j]=b[j-1];
			}
			b[0]=a[i];
		}
	}
	return 0;
}

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

C++: #include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < n; i++){
const int INF = 1 << 25;
 
stack<int> cars;
int numbar;
 
int main(){
    while(scanf("%d", &numbar) != EOF){
        if(numbar == 0){
            printf("%d\n", cars.top());
            cars.pop();
            continue;
        }
        cars.push(numbar);
    }
    return 0;
}

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>

using namespace std;

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

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

int main(){
	vector<int> v;
	stack<int> s;
	int n;
	cin >> n;
	s.push(n);
	while(!s.empty()){
		cin>>n;
		if(n==0){
			v.push_back(s.top());
			s.pop();
		} else {
			s.push(n);
		}
	}
	for(int i=0 ; i<v.size(); i++){
		cout << v[i] << endl;
	}
	return 0;	
}