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 <stdio.h>

int main(void){
	int i;
	int train[11]={0};
	int t,now=0,count=0;
	int car[11]={0};
	
	for(;;){
		scanf("%d",&t);
		if(t!=0){
			train[now]=t;
			now++;
		}
		else{
			now--;
			car[count]=train[now];
			train[now]=0;
			count++;
			if(now==0)break;
		}/*0
		printf("now=\n");
		for(i=0;i<10;i++){
			printf("car[%d] = %d\n",i,car[i]);
		}
		for(i=0;i<10;i++){
			printf("train[%d] = %d\n",i,train[i]);
		}
		*/
	}
	
	i=0;
	while(car[i]!=0){
		printf("%d\n",car[i]);
		i++;
	}
	
	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(j1!=0){
printf("%d",a[j1]);
break;
}
j--;
}
}
}

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

using namespace std;

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

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

	return 0;
}

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

C++: #include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>


using namespace std;

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

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

using namespace std;

int main()
{
	stack<int> hako;
	int temp[100];
	int input[100];
	int t, i = 0, k = 0;
	
	
	while(cin>>t){
		input[i] = t;
		i++;
	}
	
	/*
	while(1){
		cin >> t;
		if( t == -1){
			break;
		}
		input[i] = t;
		i++;
	}
	*/
	for(int j = 0; j < i; j++){
		if(input[j] == 0){
			temp[k] = hako.top();
			hako.pop();
			k++;
		}
		else{
			hako.push(input[j]);
		}
	}
	
	for(int j = 0; j < k; j++){
		cout << temp[j] << endl;
	}
	
}

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

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

stack<int> sta;

int main()
{
  int a;
  while(1){
    cin>>a;
    if(a)
      sta.push(a);
    else{
      cout<<sta.top()<<endl;
      sta.pop();
    }
  }
}

C++: #include <stdio.h>
 
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 <stdio.h>

int main() {
	int temp[10];
	int input;

	int i = 0;
	
	while(scanf("%d", &input) != EOF) {
		if(input != 0) {
			temp[i] = input;
			i++;
		}

		else {
			i--;
			printf("%d\n", temp[i]);
		}
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a[10],i=0,n;
	while(scanf("%d",n)==1){
		if(n!=0){
			a[i]=n;
			i++;
		}
		else{
			i--;
			cout<<a[i]<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
class stack{
	int row[10];
	int top;
	public:
		stack(){top = 0;}
		void push(int x);
		int pop();
};
void stack::push(int x){
	row[top] = x;
	top++;
}
int stack::pop(){
	top--;
	return row[top];
}
int main(){
	stack cars;
	int k;
	while(cin >>k){
		if(k == 0){cout<<cars.pop()<<endl;}
		else{cars.push(k);}
	}
	return 0;
}

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

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

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

using namespace std;

int main(int argc, char const *argv[]){
    int input; 
    stack<int> train_stack;
    vector<int> order;

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

    return 0;
}

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

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

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

using namespace std;

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

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

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int main(){
    stack<int> densha;
    for(int a; cin >> a; ){
        if(a == 0){
            cout << densha.top() << endl;
            densha.pop();
        }else
          densha.push(a);
    }
    return 0;
}

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

int main( void )
{
	stack <int> S;
	int first;
	cin >> first;
	S.push( first );

	string kotae = "";
	while ( S.empty() == false )
	{
		int n;
		cin >> n;
		if ( n == 0 )
		{
			ostringstream os;
			os << S.top() << endl;
			kotae += os.str();
			S.pop();
		}
		else
		{
			S.push( n );
		}
	}

	cout << kotae;

	return 0;
}

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

bool listen_input(int &);

void exec_order(std::stack<int> &,const int);

//--------------------main-------------------------
int main()
{
	using namespace std;
	
	stack<int> carStop;
	
	int order;
	while(listen_input(order))
	{
		exec_order(carStop,order);
	}
	
	return 0;
}
//-------------------------------------------------

bool listen_input(int &order)
{
	using namespace std;
	
	cin>>order;
	if(cin.eof())
	{
		return false;
	}
	else
	{
		return true;
	}
}

void exec_order(std::stack<int> &carStop,const int order)
{
	using namespace std;
	
	if(order)
	{
		carStop.push(order);
	}
	else
	{
		cout<<carStop.top()<<endl;
		carStop.pop();
	}
}

C++: #include <iostream>
#include<string>
#include<algorithm>
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 <stack>

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

	//car's number
	int num = 0;

    //Until the end of input
	while(std::cin >> num){
        //if num = 0, output and delete
		if(num == 0){
			std::cout << st.pop() << std::endl;
        //if num != 0, input    
		} else {
			st.push(num);
		}
	}
}