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 <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define INF 1<<25
#define LIM 1000000

using namespace std;

stack<int> st;
int a;

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

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

int main(){
    stack<int> rail;
    int buf;
    
    // repeat until "cin" fails.
    while (cin >> buf) {
        if (buf == 0) { // train goes out.
            cout << rail.top();
            rail.pop();
        }
        else{   // train comes in.
            rail.push(buf);
        }
    }
    
    return 0;
}

C++: #include<stdio.h>
int main(void){
	char tr[30];
	int i=0,j,k,l,in[10]={ 0 },out[10]={ 0 };
	while(scanf("%d",&tr[i])!=EOF){i++;}
	
	for(j=0,k=0,l=0;j<i;j++){
		switch(tr[j]){
			case 1:
				in[k]=1;
				k++;
				break;
			case 2:
				in[k]=2;
				k++;
				break;
			case 3:
				in[k]=3;
				k++;
				break;
			case 4:
				in[k]=4;
				k++;
				break;
			case 5:
				in[k]=5;
				k++;
				break;
			case 6:
				in[k]=6;
				k++;
				break;
			case 7:
				in[k]=7;
				k++;
				break;
			case 8:
				in[k]=8;
				k++;
				break;
			case 9:
				in[k]=9;
				k++;
				break;
			case 10:
				in[k]=10;
				k++;
				break;
			case 0:
				k--;
				out[l]=in[k];
				l++;
				break;
			default :
				break;
		}
	}
	for(i=0;i<l;i++){
		printf("%d\n",out[i]);
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main() {
	int train[20] = { 0 }, junban[20] = { 0 }, a = 0, n, i;	
	while (cin >> n) {
		if (n == 0) {
			for (i = 0; train[i] != 0; i++) {}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; train[i] != 0; i++) {}
			train[i] = n;
		}
	}
	for (i = 0; junban[i] > 0; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main() { 
  int n;
  vector<int> a;
  vector<int>::iterator it; 
  while(cin >> n) {  
    if(n==0) {    
      it=a.end();  
      it--;   
      cout << *it << endl;  
      a.erase(it); 
    } else {    
      a.push_back(n); 
    } 
  } 
  return 0;
}

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

using namespace std;

int main()
{
	int a, i;
	
	stack<int> syaryo;
	
	
	for(i = 0; i < 10; i++)
	{
		cin >> a;
		if(a != 0)
		{
			syaryo.push(a);
		}
		else
		{
			cout << syaryo.top() << endl;
			syaryo.pop();
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

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

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<stack>

using namespace::std;

int main(){
  stack<int> st;
  int i = 0;
  int val = 0;

  while(scanf("%d", &val) != EOF){
    if(val == 0){
      cout << st.top() << endl;
      st.pop();
      continue;
    }
    st.push(val);
  }

  return 0;
}

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

using namespace std;

int main() {
	list<int> stat;

	for (int i = 0, in; cin >> in; i++, stat.push_back(in));

	stack<int> stacK;
	for (list<int>::iterator it = stat.begin(); it != stat.end(); it++, it = stat.begin()) {
		if (*it == 0) {
			cout << stacK.top() << endl;
			stacK.pop();
		} else
			stacK.push(*it);
		stat.pop_front();
	}
}

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

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define INF 1<<25
#define LIM 1000000

using namespace std;

stack<int> st;
int a;

int main()
{
	
	cin >> a;
	st.push(a);
	
	while(!st.empty())
	{
		cin >> a;
		
		if( a == 0 )
		{
			cout << st.top() << endl;
			st.pop();
		}
		else
			st.push(a);
	}
	
	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=cars.size()-1;
	while (cin >> temp) {
		if (temp != 0) {
			cars.push_back(temp);
		} else {
			ans.push_back(cars.at(i));
			i--;
		}
	}
	for (int j=0; j<ans.size(); j++)
		cout << ans[j] << endl;
	return 0;
}

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

int main(){
	int a[30];
	int i = 0;

	for (int i = 0; i < 30; i++){
		a[i] = 0;
	}

	while (1){
		i++;
		cin >> a[i];
		if (a[i] == 0){
			int j = i+1;
			while (1){
				j--;
				if (a[j] != 0){
					cout << a[j] << endl;
					a[j] = 0;
					break;
				}
			}
		}
	}


	return 0;
}

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

int main( void )
{
	stack <int> S;
	int first;
	cin >> first;
	S.push( first );

	string kotae = "";
	while ( S.empty() == false )
	{
		int n;
		cin >> n;
		if ( n == 0 )
		{
			kotae += ('0' + S.top());
			kotae += '\n';
			S.pop();
		}
		else
		{
			S.push( n );
		}
	}

	cout << kotae;

	return 0;
}

C++: #include <stdio.h>

#define N 20
int main(void){
    int stk[N], sp=0;
    int n;
   
    while (scanf("%d", &n)){
        if (n==0 && sp!=0){
            printf("%d\n", stk[--sp]);
        } else {
            stk[sp++] = n;
        }
    }
    return 0;
}

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

vector<int> car,ans;

int main()
{
	while(true) {
		int n;
		scanf("%d",&n);
		if(n != 0) { car.push_back(n); }
		else {
			ans.push_back(car.back());
			car.pop_back();
		}
		if(car.empty()) { break; }
	}
	int Size = ans.size();
	for(int i=0;i<Size;++i) printf("%d\n",ans[i]);
	return 0;
}