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(void){
		int train[100];
		int count = 0;
		int n;
		while(cin >> n){
			if(n > 0){
				train[count] = n;
				count++;
			}else if(n == 0){
				count--;
				cout << train[count] << endl;
			}
		}
		return 0;

	}

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

using namespace std;

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

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

using namespace std;
long long int num;
stack<int> s;

int main(){
	cin >> num;
	if(num!=0){
		s.push(num);
	}
	while(!s.empty()){
		cin >> num;
		if(num!=0){
			s.push(num);
		}
		else{
			cout << s.top() << endl;
			s.pop();
		}
	}
	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>
using namespace std;
#define N 11
int push();
int pop();
 int top=0;
  int buffer[N];
  int num;
  int out[N];
  int status;


int main(void){
 
  while(1){
    
    status = scanf("%d", &num);
    if(status == EOF)break;
    if(num != 0)push();
    else if(num == 0){
      cout << pop() << endl;
    }
  }
  
  
  return 0;
}

int push(){
  
  top++;
  buffer[top]=num;
}

int pop(){
  int x=buffer[top];
  top--;
  return x;
}

C++: #include <cstdio>
#include <vector>
int main(){
	int n;
	std::vector<int> v;
	while(scanf("%d\n", &n)+1){
		if(n){
			v.push_back(n);
		}else{
			printf("%d\n", v.back());
			v.pop_back();
		}
	}
	return 0;
}

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

int s[10],t;

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

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

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

C++: #include<stdio.h>

int main(){
	int car[10];
	int a,c=0;
	while(~scanf("%d",&a)){
		if(a==0){
			printf("%d",car[c]);c--;
		}
		else {
			car[c]=a;
			c++;
		}
	}
}

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

int main()
{
	std::vector<int> train;

	std::vector<int> out;

	int n;

	while(std::cin >> n)
	{
		if(n!=0)
		{
			train.push_back(n);
		}
		else
		{
			out.push_back(train[train.size()-1]);

			train.pop_back();
		}
	}

	for(size_t i=0;i<out.size();++i)
	{
		std::cout << out[i] << '\n';
	}
}

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

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

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

int main()
{
	stack<int> car;
	vector<int> outlist;

	while( !car.empty() || outlist.empty() )
	{
		int carnum;
		cin >> carnum;
		if(carnum)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}

	cout << '\n';
	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

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

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

int main(void){
	int n;
	vector<int> car;

	cin >> n;
	car.push_back(n);

	while(cin >> n){
		if(n!=0) car.push_back(n);
		else{
			cout << car.back() << endl;
			car.pop_back();
		}
	}
	return 0;
}

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

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

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

int main() {
  stack<int> sta;
  
  while(1){
  
    int temp;
    cin >> temp;
    
    if (temp==0){
      if (sta.empty()){
	cout << sta.top() <<endl;
	sta.pop();
	if (sta.empty()) break;
      }
    }else{
      sta.push(temp);
    }
  }
    
  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++: //Switching Railroad cars

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

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

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

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

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

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

using namespace std;

int main() {
  int n;
  vector<int> train;

  while (cin >> n) {
    if (n) {
      train.push_back(n);
    }
    else {
      cout << train.back() << endl;
      train.pop_back();
    }
  }
  return 0;
}

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

int main(){
	int n;
	vector <int> g;
	while(true){
		cin>>n;
		if(n!=0){
			g.push_back(n);
		}else{
			n=g.back();
			g.pop_back();
			cout<<n<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>

int main(){
  int i,a;
  int train[1000];

  i = -1;

  while(std::cin >> a){
    if(a == 0){
      std::cout << train[i] << std::endl;
      --i;
      continue;
    }
    ++i;
    train[i] = a;
  }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <ctime>
#include <cmath>
#include <cassert>
#include <limits>
#include <functional>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(int)(n);++(i))

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

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;
		}
	}
	
	
	return 0;
}