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


using namespace std;

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

C++: #include<iostream>
using namespace std;
int main(){
  int number,count1,count2,enter[11],leave[11],sum;
  sum=0;
  count1=0;
  count2=0;
  while(1){
    
    if( cin >> number && number>=0 && number<=10){
    
    if(number!=0){
      sum++;
      enter[count1]=number;
      count1++;}
    else if(number==0){
      count1--;
      leave[count2]=enter[count1];
      count2++;}
    if(sum-1<count2)break;
    }}
  for(int i=0;i<count2;i++){
    cout << leave[i]<< endl;
  }
 
  return 0;
}

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

int main() {
  int i;
  int cnt = 0;
  std::vector<int> vec;
  while(cnt < 50) {
    scanf("%d", &i);
    if(i == 0){
      printf("%d\n", vec.back());
      vec.pop_back();
    }else{
      vec.push_back(i);
    }
    cnt++;
  }
  return 0;
}

C++: #include <stdio.h>
#include <vector>
using namespace std;

int main() {
    vector<int> v;
    int a;
    while (scanf("%d", &a) != EOF) {
        if (a != 0) v.push_back(a);
        else {
            printf("%d\n", v.back());
            v.pop_back();
        }
    }
    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);
    }
    return 0;
}

C++: #include <stdio.h>

int main(void) {

  int car;
  int cars[10];

  int top=0;

  while(scanf("%d",&car)!=EOF) {

    if(car==0) {
      
      top--;
      printf("%d\n",cars[top]);

    }
      
    else {
      
      cars[top]=car;
      top++;

    }

  }

  return 0;

}

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


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

    return 0;
}

C++: #include<stdio.h>
int main(void){
	char tr[30];
	int i=0,k,l,in[10]={ 0 },out[10]={ 0 };
	for(k=-1,l=0;;i++){
		scanf("%d",&tr[i]);
		switch(tr[i]){
			case 1:
				k++;
				in[k]=1;
				break;
			case 2:
				k++;
				in[k]=2;
				break;
			case 3:
				k++;
				in[k]=3;
				break;
			case 4:
				k++;
				in[k]=4;
				break;
			case 5:
				k++;
				in[k]=5;
				break;
			case 6:
				k++;
				in[k]=6;
				break;
			case 7:
				k++;
				in[k]=7;
				break;
			case 8:
				k++;
				in[k]=8;
				break;
			case 9:
				k++;
				in[k]=9;
				break;
			case 10:
				k++;
				in[k]=10;
				break;
			case 0:
				out[l]=in[k];
				in[k]=0;
				k--;
				l++;
				break;
			default :
				break;
		}
		if(in[0]==0){break;}
	}
	for(i=0;i<l;i++){
		printf("%d\n",out[i]);
	}
	return 0;
}

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

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

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


int main(){
  int num;
  stack<int>st;
  cin>>num;
  st.push(num);
  while(st.size()!=0){
    cin>>num;
    if(num==0){
      cout<<st.top()<<endl;
      st.pop();
    }
    else{
      st.push(num);
    }
  }
  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<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
vector<int> vec;

int main() {

	while(1){
		int n;
		cin>>n;
		if(cin.eof())break;
		if(n==0){
			cout<<vec[vec.size()-1]<<endl;
			vec.pop_back();
		}else vec.push_back(n);
	}

	return 0;
}

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

int main ()
{
    std::stack<u_int> cars;
    u_int number;

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

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <complex>
#include <iterator>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i, a, cont, next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i, a, b, step) repfn(i, a, i < b, i + step)
#define repab(i, a, b) repby(i, (a), (b), 1)
#define rep(i, n) repab(i, 0, (n))
#define pb push_back
#define sz(c) int((c).size())

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

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

using namespace std;

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

    return 0;
}

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

using namespace std;

int main() {
  stack<int> cars;
  string line;
  while (getline(cin, line)) {
    int car = atoi(line.c_str());
    if (car == 0) {
      cout << cars.top() << endl;
      cars.pop();
    } else {
      cars.push(car);
    }
  }

  return 0;
}

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

int main(){
	int a[100];
	int i = 0;

	while (1){
		cin >> a[i];
		if (a[i] == 0){
			int j = i;
			while (1){
				j--;
				if (a[j] != 0){
					cout << a[j] << endl;
					a[j] = 0;
					break;
				}
			}
		}
		i++;
	}


	return 0;
}

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

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

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