Go: package main

import "fmt"

func main() {
	var i int
	stack := make([]int, 0)
	for {
		v, _ := fmt.Scan(&i)
		// fmt.Println(stack)
		// println(v)
		if v == 0 {
			break
		}
		if i == 0 {
			fmt.Println(stack[len(stack)-1])
			stack = stack[:len(stack)-1]
			continue
		}
		stack = append(stack, i)
	}
}

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


stack<int> S;
int N;

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

	return 0;
}

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

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

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

  cin >> n;
  s.push(n);

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

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

int main()
{
    vector<int> entered_cars;
    int number;

    while (cin >> number)
    {
        if(number == 0)
        {
            int& x = entered_cars.back();
            cout << x << endl;
            entered_cars.pop_back(); 
        }
        else
        {
            entered_cars.push_back(number);
        }
    }

    return 0;
}

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

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

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

using namespace std;


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

}

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

using namespace std;

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

C++: #include<iostream>
using namespace std;
int main(){
  int i=0,num,a[10],x=0;
  
  while(cin>>num){
    if(num==0)cout<<a[--i]<<endl;
    else  a[i++]=num;
  } 
  return 0;
}

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

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

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

C++: #include<iostream>
#include<stack>
using namespace std;
int main(void){
	int num;
	stack<int> st;

	while(cin>>num){
		st.push(num);
		if(num==0){
			st.pop();//0ツづーツ渉慊つュ
			cout<<st.top()<<endl;
			st.pop();
		}
	}
	return 0;
}

C++: #include<cstdio>

int main(){
	int g[10];
	int i = 0;
	int t;
	while(scanf("%d", &t) + 1){
		if(t){
			g[i] = t;
			i++;
		}else{
			i--;
			printf("%d\n", g[i]);
		}
	}
	return 0;
}

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

int main(){
	stack<int> st;
	int n, a;

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

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

int main(){
	std::stack<int> switching_rail;
	std::queue<int> out_number;
	int in_number;
	//Input
	while(std::cin >> in_number){
		if(in_number == 0){
			out_number.push(switching_rail.top());
			switching_rail.pop();
		}else{
			switching_rail.push(in_number);
		}
	}
	//Output
	while(!out_number.empty()){
		std::cout << out_number.front() << std::endl;
		out_number.pop();
	}
	return 0;
}

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

using namespace std;
int main(int argc, char const* argv[])
{
	stack<int> data;
	int n;

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

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

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

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

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

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

int main() {
	int n, count = 0, a[11], i;
	stack<int> s;
	while (cin >> n) {
		if (n > 0) s.push(n);
		else if (n == 0) {
			a[count++] = s.top();
			s.pop();
		}
	}
	for (i = 0; i < count; i++) {
		cout << a[i] << endl;
	}
}

C++: #include <stdio.h>
#include <stack>

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