Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	n, err := strconv.Atoi(nextString())
	return n, err
}

func main() {
	scanner.Split(bufio.ScanWords)

	stack := []int{}
	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		if n == 0 { // pop
			fmt.Println(stack[len(stack)-1])
			stack = stack[0:(len(stack) - 1)]
		} else { // push
			stack = append(stack, n)
		}
	}
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(void) {
	int input_num;
	vector<int> train_num;
	while (cin >> input_num) {
		if (input_num == 0) {
			cout << train_num.back() << endl;
			train_num.pop_back();
		}
		else{
			train_num.push_back(input_num);
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

	int i, j=0, n, a[10], b[10];

	for(i=0; i<10; i++) {
		b[i]=0;
	}

	for(i=0; i<10; i++) {
		cin >> n;
		if(n==0) {
			b[j]=a[i-1];
			j++;
			i--;
			a[i]=n;
			if(i==0)
				break;
			i--;
			continue;
		}
		a[i]=n;
	}

	for(i=0; b[i]!=0; i++) {
		cout << b[i] << endl;
	}

	char s;
	cin >> s;

	return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main() {
	
	int c[10],e[10],m,n=0,k=0;
	for(int i=0;i<10;i++){c[i]=0;e[i]=0;}
	
	while(cin>>m){
		if(m==0){e[k]=c[n-1];k++;c[n-1]=0;n--;}
		else {c[n]=m;n++;}
	}
	
	for(int i=0;i<k;i++)cout<<e[i]<<endl;
	
	return 0;
}

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]<<endl;
for(int i=0;i<9;i++){
a[i]=a[i+1];}}
else{
for(int i=0;i<9;i++){
a[9-i]=a[8-i];}
a[0]=b;}}}

C++: #include<stdio.h>
int main(){
int a[100];
int j;
for(int i=0;;i++){
scanf("%d",&a[i]);
if(a[i]==0){
j=i;
while(){
if(j1!=0){
printf("%d",a[j1]);
break;
}
j--;
}
a[j-1]=0;
if(j-1==0){
break;
}
}
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  stack<int> n;
  int a;
  while(cin >> a){
    if(a != 0)n.push(a);
    else{
      cout << n.top()<<endl;
      n.pop();
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

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

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

using namespace std;



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

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

int main(){
    int cnt = 0;
    int sta;
    int train[10]={0};
    while(cin >> sta){
        if(sta == 0){
            cnt--;
            cout << train[cnt] << endl;
        }
        else {
            train[cnt] = sta;
            cnt++;
        }
    }
}

C++: #include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp= 0;


int top(){
 return data[sp-1];
}
void pop(){
 sp--;
}

void push(int v){
 data[sp] = v;
 sp++;
}

int main(){
 int v;
 while(scanf("%d", &v) != EOF){
  if(v != 0){
   push(v);
  }
  if(v == 0){
   printf("%d\n", top());
   pop();
  }
 }
 return 0;
}

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

using namespace std;
int main(){
  int op;
  stack<int> intStack;
  while(cin>> op){
    if(op == 0){
      cout << intStack.top() << endl;
      intStack.pop();
    } else {
      intStack.push(op);
    }
  }
  return 0;
}

C++: #include <stdio.h>
#include <stack>
 
int main(void) {
  std::stack<int> st;
  int n;
  while(scanf("%d", &n) != EOF) {
    if(n) st.push(n);
    else {
      printf("%d\n", st.top());
      st.pop();
    }
  }
  return 0;
}

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

int main(){
	int track[100];
	int x;
	int counter=0;
	int exit[100];
	int exit_number=0;
	while(cin >> x){
		if(x==0){
			counter--;
			exit[exit_number]=track[counter];
			exit_number++;
			
		}
		else{
			track[counter]=x;
			counter++;
		}
	}
	for(x=0; x<exit_number;x++){
		cout << exit[x] << endl;
	}
}

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

C++: #include <cstdio>
#include <stack>
using namespace std;
  int main(){
   int train[11],n;
   stack<int> s;
   while(scanf("%d",&n) != EOF){
      if(n != 0){
        s.push(n);
           }else{
             printf("%d\n",s.top());
			 s.pop();
         }
}
return 0;
}

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

int main(){
  stack<int> S;

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

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 <stack>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

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

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

int main(){

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


  }


  return 0;

}

C++: #include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

int a[25]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int b,c;

int main()
{
	b=0;
	while(a[0]!=0)
	{
		scanf("%d",&a[b]);
		if(a[b]==0)
		{
			for(c=24;c>=0;c--)
			{
				if(a[c]!=0)
				{
					printf("%d\n",a[c]);
					a[c]=0;
					break;
				}
			}
		}
		b++;
	}
	return 0;
}