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 "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

bool isAbove(pair<double, double> p1, pair<double, double> p2, pair<double, double> p3) {
	if (p1.first == p2.first) {
		return p3.first > p1.first;
	} else {
		return p3.second > p1.second + (p2.second - p1.second) * (p3.first - p1.first) / (p2.first - p1.first);
	}
}

void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif

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


}




int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	solve();
	return 0;
}

C++: #include <cstdio>

int main(void) {
	int souko[10], now=0;
	int input;

	while(scanf("%d", &input) != EOF) {
		if(input == 0) {
			now--;
			printf("%d\n", souko[now]);
		} else {
			souko[now] = input;
			now++;
		}
	}

	return 0;
}

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

int main(){
	std::vector<int> out;
	std::vector<int> stock;
	int a;
	while( std::cin >> a ){
		if( a == 0 ){
			out.push_back(stock.back());
			stock.pop_back();
		}
		else{
			stock.push_back(a);
		}
	}
	
	for(unsigned int i=0; i<out.size(); ++i){
		std::cout << out[i] << std::endl;
	}
	
	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);
    }
  }
    return 0;
  }

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

using namespace std;

int main()
{
	int n,right,i=0;
	vector<int> train;
	while(cin>>n)
	{
		vector<int>::iterator it = train.begin();
		while(it!=train.end()) ++it;
		if(n==0)
		{
			--it;
			right = *it;
			cout<<right<<endl;
			train.pop_back();
			i++;
		}
		else
		train.push_back(n);
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<bitset>
#define INF 1001001001
#define EPS 0.000000001

using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pint;

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
//int dx[8] = {0,1,1,1,0,-1,-1,-1};
//int dy[8] = {1,1,0,-1,-1,-1,0,1};


int main(){
	int i[100];
	int p=-1;
	int in;
	while(cin >> in){
		if(in==0){
			cout << i[p] << endl;
			p--;
		}
		else{
			p++;
			i[p]=in;
		}
	}
	return 0;
}

C++: #include<iostream>
#include <stdio.h>
#include <vector>
using namespace std;
vector<int> vec;
vector<int>::iterator itr=vec.end();
int main(){int a;
while(cin>>a){
	if(a==0){itr=vec.end();itr--;cout<<*itr<<endl;
		vec.pop_back();
}else{
	vec.push_back(a);}}
	return 0;}

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

int main(void){
     int n[10];
     int i=0;
     int d;
     do{
	  cin >> d;
	  if(d == 0){
	       cout << n[i-1] << endl;
	       i = i-1;
	  }else{
	       n[i] = d;
	       i = i+1;
	  }
//	  cout << endl;
//	  for(int i=0;i<10;i++){
//	       cout << n[i-1] << endl;
//	  }
//	  cout << endl;
     }while(i!=0);

     return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

    int i = 0,j,k = 0,n,grage[100],box[100];
    
    while(cin >> n){
        box[i] = n;
        i++;
    }
    
    for(j = 0;j < i;j++){
        if(box[j] != 0){
            grage[k] = box[j];
            k++;
        }
        else {
            cout << grage[k - 1] << endl;
            k--;
        }
    }
    
    return 0;
}

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

int main(){
	std::vector<int> rail;
	std::vector<int> out;
	int a;

	while(std::cin >> a){
		if(a != 0){
			rail.push_back(a);
		}else if(a == 0){
			out.push_back(rail.back());
			rail.pop_back();
		}
	}

	for(int i=0; i<(int)out.size(); ++i){
		std::cout << out.at(i) << std::endl;
	}
}

C++: #include<bits/stdc++.h>

using namespace std;

int str1[11],str2[11],mo;

int  s=1,t1,t2;

int main(){


    while(1){

    cin >> mo;


    if(mo!=0){
        str1[t1]=mo;
        t1++;

    }else {
        str2[t2++]=str1[--t1];

    }

    if(t1==0)break;

    }

    for(int i=0;i<11;i++){

            if(str2[i]==0)break;
        cout << str2[i] << endl;
    }


return 0;
}

C++: /*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main()
{
int x=0,y=0,z=0,w=0,n=0;
string b;
stack<int> s;
while(std::cin >> x){
  if(x==0){
    std::cout << s.top() << '\n';
    s.pop();
  }else{
    s.push(x);
  }
}

}

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

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

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

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

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

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    int a;
    vector<int> s;
    vector<int> t;
    while(cin>>a){
        if(a!=0){
            s.push_back(a);
        }else{
            s.pop_back();
            t.push_back(s[s.size()-1]);
            s.pop_back();
        }
    }
    for(int i=0;i<t.size();i++){
        cout << t[i] << endl;
    }
    return 0;
}

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

int main(){
	stack<int> garage;

	int car = 0;
	while(cin >> car){

		if(car != 0){
			garage.push(car);
		}else{
			cout << garage.top() << endl;
			garage.pop();
		}
	}
	return 0;
}

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

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