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;
int main(){
int a[]={0,0,0,0,0,0,0,0,0,0};
int b;
while(cin>>b){
if(b==0){
cout<<a[0];
for(int i=0;i<9;i++){
a[i]=a[i+1];}}
else{
for(int i=0;i<8;i++){
a[9-i]=a[8-i];}
a[0]=b;}}

C++: #define scanf_s scanf
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 150
int main(void)
{
	int w, n, now = 0, cou = 0;
	int list[MAX] = { 0 };
	int li[MAX] = { 0 };
	do{	
		scanf_s("%d", &n);
		if (n != 0) { list[now] = n; ++now; }
		else { --now; 	printf("%d\n", list[now]);}
	} while (now != 0);
}

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

int main()
{
	int n;
	int cnt = 0;
	stack<int> car;
	vector<int> out;

	while (cin >> n){
		if (n == 0){
			out.push_back(cnt);
			out[cnt] = car.top(); // top pop
			car.pop();
			cnt++;
		}
		else {
			car.push(n);
		}
	}

	for (int i = 0; i < cnt; i++){
		cout << out[i] << endl;
	}

	return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,a[1000]={},cnt=0;
	while(cin >> n){
		if(n==0){
			cout << a[cnt-1] << endl;
			cnt--;
		}else{
			a[cnt]=n;
			cnt++;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
int x;
stack<int>s;
int main() {
	while (cin >> x) {
		if (x)s.push(x);
		else {
			cout << s.top() << endl;
			s.pop();
		}
	}
	
	getchar();getchar();
	return 0;
}

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