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 <stdio.h>  

int main(){
    int hi[10];
    int n,count=0;
    while(scanf("%d",&n) != EOF){
	if(n == 0){
	    printf("%d\n",hi[count-1]);
	    hi[count-1]=0;
	    count--;
	}
	else{
	    hi[count]=n;
	    count++;
	}
    }
    return 0;  
}

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

int main(){
	int num;
	stack<int> s;
	cin >> num;
	if(num!=0){
		s.push(num);
	}
	while(!s.empty()){
		cin >> num;
		if(num!=0){
			s.push(num);
		}
		else{
			cout << s.top() << "\n";
			s.pop();
		}
	}
	return 0;
}

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

using namespace std;

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

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

C++: #include<iostream>
using namespace std;
int main(){
  
  int a[10],c=0,num;

  while(1){

    cin >>num;

    if(num >= 1 && num <=10){
      a[c]=num;
      c++;
    }else{
      cout <<a[c-1]<<endl;
      c--;
    }   

  }
  return 0;

}

C++: #include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main() {
  stack<int> s;
  vector<int> v;
  int n;
  while (cin >> n) {
    if (n == 0 && !s.empty()) {
      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;
}

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

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

using namespace std;

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

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

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

stack<int> st;

int main() {
	for(int p; cin >> p;) {
		if(p == 0) {
			printf("%d\n", st.top());
			st.pop();
		} else {
			st.push(p);
		}
	}
	return 0;
}

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

C++: #include<iostream>
using namespace std;
int main()
{
    int train[10]={0},n,count=0,outTrain[10],trainCount=0;
    while(cin >> n){
        if(cin.eof())break;
        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++){
        cout << outTrain[i] << '\n';
    }
    return 0;
}

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

using namespace std;

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

C++: //0013
#include <bits/stdc++.h>
using namespace std;

int main(){
	int tmp,i = 0,j,k = 0,f[11];
	vector<int> ans;

	while(cin>>tmp){
		if(tmp == 0){
			ans[k] = f[i-1];
			f[i-1] = '\0';
			i--;
			k++;
		}
		else{
		f[i] = tmp;
		i++;
		}
	}
	for(j = 0;j < k;j++){
		cout<<ans[j]<<endl;
	}
	return 0;
}

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

int main()
{
	int n = 0;
	stack<int>s;
	bool flag = false; 

	while (1){
		cin >> n;

		if (n == 0){
			
			cout << s.top() << endl;
			s.pop();
			if (s.empty()){
				break;
			}
		}else{
			s.push(n);
		}
	}



	return 0;
}

C++: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue< pair<int, int> > qpii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector< pair<int, int> > vpii;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

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

	stack<int> s;
	int k;

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

	return 0;
}

C++: #include <stdio.h>

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

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

int main(){
	int out[10], car[10];
	int x, k = 0, i = 0;
	while(cin >> x){
		if(x != 0){
			car[i] = x;
		}
		else{
			out[k] = car[i-1];
			i = i-2;
			k++;
		}
		i++;
	}
	for(int j = 0; j < k; j++){
		cout << out[j] << endl;
	}
}

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

using namespace std;

int main()
{
int a;
vector<int> array;
for(;cin >> a;)
{
if(a==0)
{
cout << array[array.size()-1] << endl;
array.pop_back();
}
else
array.push_back(a);
}
}

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

using namespace std;

stack<int>s;

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

C++: //Switching Railroad Cars
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;

int main(void){
    stack<int> Q;
    int n;
    
    while((scanf("%d", &n) != EOF)){
        if(n == 0){
            int  x = Q.top(); Q.pop();
            printf("%d\n", x);
        }else{
            Q.push(n);
        }
    }
    
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<sstream>
#include<stack>
using namespace std;
int main(){
	stack<int> train;
	int a;
	while(cin>>a){
		int now;
		if(a==0){
		now=train.top();
		train.pop();
		cout<<now<<endl;
		}
		else {
			train.push(a);
		}
	}
	
    return 0;
}