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<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    stack <int> st;
    while(cin>>n){
            if(n==0){
                if(st.empty()){
                    continue;
                }
                cout<<st.top()<<endl;
                st.pop();
            }
            else{
                st.push(n);

            }

    }


    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;

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

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

string str1[11],str2[11],mo;

int  s=1,t1,t2;

int main(){


    while(1){

    cin >> mo;


    if(mo!="0"){
        str1[t1]=mo;
        t1++;

    }else {
        str2[t2++]=str1[--t1];

    }

    if(t1==0)break;

    }

    for(int i=0;i<11;i++){

            if(str2[i]=="0")break;
        cout << str2[i] << endl;
    }


return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

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

C++: #include <stdio.h>

int main(void)
{
	int num[10];
	int in;
	int ord[10];
	int i;
	
	for (i = 0; i < 10; i++){
		num[i] = 0;
	}
	while (scanf("%d", &in) == 1){
		if (in != 0){
			for (i = 0; i < 10; i++){
				if (!num[i]){
					num[i] = in;
					break;
				}
			}
		}
		else {
			for (i = 9; i >= 0; i--){
				if (num[i] != 0){
					printf("%d\n", num[i]);
					num[i] = 0;
					break;
				}
			}
		}
	}
	
	return (0);
}

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

using namespace std;       
int main(){
  stack<int> s;
  int a;
  while(cin >> a){
    if(a != 0){
      s.push(a);
    }else{
      cout << s.top()<< endl;
      s.pop();
    }
    if(s.size() == 0)
      break;
  }
  return 0;
}

C++: #include <stdio.h>

int train[10];
int sp = 0;

int empty() {
  return sp <= 0;
}

int size() {
  return sp;
}

int top() {
  return train[sp-1];
}

void pop() {
  sp--;
}

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

int main(){
  int num;
  while(1){
    scanf("%d", &num);
    if(num == 0){
      printf("%d\n", top());
      pop();
    }else if(1 <= num && num <= 10){
      push(num);
    }
    if(size() == 0) break;
  }
  return 0;
}

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++: #include <iostream>
#include <stack>
 
using namespace std;
 
int main(){
  stack<int> trains;
  int p;
  while(cin >> p){
    if(p == 0){
      cout << trains.top() << endl;
      trains.pop();
    }else{
      trains.push(p);
    }
  }
  return 0;
}

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

int main(){
  stack<int> st;
  int a;
  while(cin>>a){
    if(a)st.push(a);
    else {printf("%d\n",st.top());
      st.pop();
    }
}

   
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(void)
{
    vector<int> t;
    int a;
    while (true)
    {
        cin >> a;
        if (a != 0)
        {
            t.push_back(a);
        }
        else if (a == 0)
        {
            cout << t.back() << endl;
            t.pop_back();
        }
        if (t.empty())
        {
            break;
        }
    }
}

C++: #include<iostream>
#include<vector>
int main()
{
	std::vector<int>num;
	for (int i; std::cin >> i;)
	{
		if (i == 0)
		{
			std::cout << num.back() << std::endl;
			num.pop_back();
		}
		else
		{
			num.push_back(i);
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

double dot(P a,P b){return real(conj(a)*b);};
double cross(P a,P b){return imag(conj(a)*b);};

int main(){
  stack<int> st;
  int x;
  while(~scanf("%d",&x)){
    if(x == 0){
      cout<<st.top()<<endl;
      st.pop();
    }else{
      st.push(x);
    }
  }
  return 0;
}

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

int main(){
	std::deque<int> que;
	int tmp;
	while(std::cin >> tmp){
		if(tmp == 0) std::cout << que.pop_back() << std::endl;
		else que.push_back(tmp);
	}
		return 0;
	}

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(j-1!=0){
printf("%d",a[j-1]);
break;
}
j--;
}
a[j-1]=0;
if(j-1==0){
break;
}
}
}

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

using namespace std;

const int N = 1000000;

int stack[N], top = 1;

int main() {
	int n;
	top = -1;
	scanf ("%d", &stack[++top]);
	while (top >= 0) {
		scanf ("%d", &n);
		if (n) stack[++top] = n;
		else printf ("%d\n", stack[top--]);
	}
	return 0;
}

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

using namespace std;

int main(){
	stack<int> st;

	while( 1 ){
		int inout;
		cin >> inout;
		if(cin.eof()) break;

		if(inout == 0){
			cout << st.top() << endl;
			st.pop();
		}else{
			st.push(inout);
		}
	}
	return 0;
}

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

using namespace std;

void solve()
{
	int n;
	stack<int> Stack;
	while(cin >> n)
	{
		if(n != 0)
		{
			Stack.push(n);
		}
		else
		{
			cout << Stack.top() << endl;;
			Stack.pop();
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(){
  int train[10];
  int by[10];
  int a,i=0,j=0,c=0;
  while(scanf("%d",&a)){
    if(a==0){
      i--;
      by[j]=train[i];
      j++;
      c--;
      if(c==0)break;
    }
    else{
      train[i]=a;
      i++;
      c++;
  }
  }
  for(int i=0;i<j;i++){
    cout<<by[i]<<endl;
  }
}

C++: #include<stdio.h>
int main(){
  int sp=0,data[9],n,i;
  for(i=0;i<100;i++){
    scanf("%d",&n);
    if(n==0 && sp>0){
      sp--;
      printf("%d\n",data[sp]);
    }else{
      data[sp]=n;
      sp++;
    }
    if(sp==0)break;
  }
  return 0;
}