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>
using namespace std;
int main(){
    int car[105];
    int num;
    int i=0;
    while(1){
        cin>>num;
        if(num!=0){
            car[i]=num;
            i++;}
        else{
            i--;
            cout<<car[i]<<endl;
            car[i]=0;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()

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

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

using namespace std;

int main(void) {
  int num;
  stack<int> stk;

  while(cin >> num) {
    if(num == 0) {
      cout << stk.top() << endl;
      stk.pop();
    }
    else {
      stk.push(num);
    }
  }
  return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
    stack<int>  s;
    int x;
    cin >> x;
    s.push(x);
    while(!s.empty()){
        cin >> x;
        if(x==0){
            cout << s.top() << endl;
            s.pop();
        }
        else{
            s.push(x);
        }
    }
}

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

int main(){
	int n;
	stack<int> stk;
	queue<int> que;
	while(1){
		cin>>n;
		if(n==0){
			que.push(stk.top());
			stk.pop();
		}else{
			stk.push(n);
		}
		if(stk.empty())break;
	}
	while(!que.empty()){
		cout<<que.front()<<endl;
		que.pop();
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

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

using namespace std;

stack<int> st;
queue<int> qu;
int a;

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

C++: #include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>

using namespace std;


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

  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int train[10000],moving,situation=0,ans[10000],n=0,ende=0;
    while(cin>>moving){
        if(moving!=0){
            train[situation]=moving;
            situation++;
        }
        else {
                situation--;
                ans[ende]=train[situation];
                ende++;
        }
    }
    for(int i=0;i<ende;i++)cout<<ans[i]<<endl;

}

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

int main(){
  vector<int> a(100);
  int n;
  while (cin >> n) {
    if (n > 0) {
      a.push_back(n);
    } else {
      cout << a.back() << endl;
      a.pop_back();
    }
  }
}

C++: list = {}
while True:
    try:
        num = int(input())
        if num == 0:
            print(list.pop())
        else:
            list.append(num)
    except:
        break

C++: #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
  int car[10],car2[10]={0};
  stack<int> rail;
  int i=0;
  while(cin >> car[i]){
    if(car[i] != 0){
      rail.push(car[i]);
	}
    else{
      cout << rail.top();
      rail.pop();
    }
    i++;
  }
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int train[10]={0},n,count=0,outTrain[10],trainCount=0;
    while(scanf("%d",&n)!=EOF){
        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>
using namespace std;

int main()
{
	int car[10],order[100],i,j,k=0;
	
	for(i=0; i<10; i++){car[i]=0;}
	i=0;
	while((scanf("%d",&order[i]))!=EOF){i++;}
	for(j=0; j<i; j++){
		if(order[j]!=0){
			car[k]=order[j];
			k++;
		}else{
			k--;
			cout << car[k] << endl;
			car[k]=0;
		}
	}
}

C++: #include <stdio.h>

int main() {
	int a,i,k,m;
	int data[15] = {0};
	int output[15] = {0};
	for (i = 0; i < 15; i++) {
		scanf("%d", &a);
		if (a != 0) {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					data[k] = a;
					break;
				}
			}
		}
		else {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					for (m = 0; m < 15; m++) {
						if (output[m] == 0) {
							output[m] = data[k - 1];
							break;
						}
					}
					data[k - 1] = 0;
					break;
				}
			}
		}
		if (data[0] == 0) {
			break;
		}
	}
	printf("\n");
	for (i = 0; i < 15; i++) {
		if (output[i] != 0) {
			printf("%d\n", output[i]);
		}
	}
	return 0;
}

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

C++: #include <iostream>

using namespace std;

int main(){
  short stack[10]={0},turn[10]={0};
  short *pstack=stack,*pturn=turn;
  while(1){
    int num;
    cin>>num;
    if(num){
      *pstack=num;
      pstack++;
    }else{
      pstack--;
      *pturn=*pstack;
      pturn++;
    }
    if(pstack==stack) break;
  }
  for(int i=0;turn[i];i++){
    if(i!=0)cout<<endl;
    cout<<turn[i];
  }
}

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

stack<int> s;
int n;

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