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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef vector<int> vi;

int main() {
	stack<int> S;
	int n;

	while(scanf("%d", &n)!=EOF) {
		if(n>0) S.push(n);
		else {
			printf("%d\n", S.top());
			S.pop();
		}
	}
}

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

int main()
{
	std::vector<std::uint16_t> cars;
	std::uint16_t num;
	while (std::cin >> num) {
		if (num == 0) {
			std::cout << cars.back() << std::endl;
			cars.pop_back();
		}
		else {
			cars.push_back(num);
		}
	}
	return 0;
}

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

using namespace std;

int main() {

	int i;
	stack<int> n;

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

	return 0;
}

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

C++: #include<iostream>
int main(){
  int stuck[10000];
  int a,count=0;
  while(std::cin>>a){
    if(a!=0){
      stuck[count]=a;
      count++;
    }else{
      std::cout<<stuck[count-1]<<"\n";
      count--;
    }
  }
}

C++: #include <stdio.h>

int main() {
	int a,i,k,m;
	int data[15] = {0};
	int output[15] = {0};
	while(scanf("%d", &a) != EOF) {
		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;
				}
			}
		}
	}
	for (i = 0; i < 15; i++) {
		
			printf("%d\n", output[i]);
		
	}
	return 0;
}

C++: #include <stack>
using namespace std;
int main()
{
	stack<int> s;
	int k;
	while (cin >> k){
		if (0 == k){
			k = s.top();
			s.pop();
			cout << k << "\n";
		}
		else s.push(k);
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <climits>
#include <cfloat>
#include <queue>
#include <stack>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

const int INF = INT_MAX;

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

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

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

C++: //Switching Railroad Cars

//vñF0ªüÍ³ê½çStack©çpopµÄ»êðoÍµëA»êÈOÍpushµÆ¯
//üÍª³µ¢±ÆÍÛá³êÄ¢é@¿ÈÝÉpush³êéàÌÍ1`10çµ¢

//ÅÍX^bNÍóÅ é

#include<iostream>
#include<stack>
using namespace std;

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

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

int main(void){
	std::stack<int> st;
	int num;

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

C++: #include <stdio.h>
#include <math.h>
 
using namespace std;
 
class STACK{
public:
    STACK(){
        index = 0;
    }
 
    void push(int data){
        array[index] = data;
        index++;
    }
    int pop(){
        index--;
        return array[index];
    }
    bool isEmpty(){
        return index == 0;
    }
 
private:
    int array[100];
    int index;
};
 
int main(){
 
    STACK stack;
    int tmp;
    while(scanf("%d",&tmp) != EOF){
        if(tmp == 0){
            printf("%d\n",stack.pop());
        }else{
            stack.push(tmp);
        }
    }
    return 0;
}

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

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

int main()
{
    int num;
    stack<int> s;

    while( cin >> num )
    {
        if( num == 0 )
        {
            cout << s.top() << endl;
            s.pop();
        }
        else
            s.push(num);
    }
    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 <cstdio>
#include <deque>
 
using namespace std;
 
int main(){
  deque<int> st;
  int n;
  while(~scanf("%d",&n)){
    if(n){
      st.push_back(n);
    }else{
      printf("%d\n",st.back());
      st.pop_back();
    }
  }
}

C++: #include<stdio.h>
const int SIZE=100;
int data[SIZE];
int sp=0;
int size(){
  return sp;
}
int empty(){
  return sp<=0;
}
int top(){
  return data[sp-1];
}
void pop(){
  sp--;
}
void push(int v){
  data[sp]=v;
  sp++;
}
int main(){
  int n;
  while(1){
    scanf("%d",&n);
    if(n==0){
      printf("%d\n",top());
      pop();
    }else{
      push(n);
    }
    if(empty())break;
  }
  return 0;
}

C++: #include <stdio.h>

int main() {
  int train[10];
  int in;
  int i = 0;
  int ii =0;
  int out[100];
  while( scanf("%d", &in ) != EOF) {
    if( in == 0 ) {
      out[i] = train[ii-1];
      train[ii -1] =0;
      ii--;
    } else if( in != 0){
      train[ii] = in;
      out[i] = 0;
      ii++;
    }
    i++;
  }
  for( int c = 0; c < i; c++ ) {
    if( out[c] != 0 ) {
      printf( "%d\n", out[c] );
    }
  }
  return 0;
}

C++: #include <stack>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	stack<int> a;
	vector<int> o;
	int s=1,d;
	
	cin>>d;
	a.push(d);
	
	while(s!=0){
		cin>>d;
		if(d!=0) {
			a.push(d);
			s++;
		}
			else {
				s--;
				o.push_back(a.top());
				a.pop();
			}
	}
	for(int i=0;i<o.size();i++) {
		cout<<o[i]<<endl;
	}
}

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<iostream>
#include<stack>

using namespace std;

stack<int>s;

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

C++: #include <iostream>
using namespace std;
int main(){
    int a[10];
    int n=0;
    while (!cin.eof()){
        int t;
        cin>>t;
        if (t) a[n++]=t;
        else cout<<a[--n]<<endl;
    }
    return 0;
}