Go: package main

import "fmt"

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

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

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

C++: #include<stdio.h>

int	i	=	0,	result;
int	train[100];
int outtrain[100];

void	push(int	k){
	train[i]	=	k;
	i++;
}

void	pop(int train[]){
	int	a,	check	=	0;
	for(a	=	i	-	1;	a	>=	0;	a--){
		if(train[a]	!=	0){
			result	=	train[a];
			train[a]	=	0;
			check	+=	1;
		}
		if(check	!=	0)break;
	}
}


int	main(){
	int	k,	cnt	=	0;
	outtrain[100]	=	0;
	while(1){
		scanf("%d",	&k);
		push(k);
		if(k	==	0){
			pop(train);
			outtrain[cnt]	=	result;
			cnt++;
			i	-=	2;
		}
		if(i	==	0)break;
	}
	for(k	=	0;	k	<=	cnt;	k++){
		if(outtrain[k]	!=	0)printf("%d\n",	outtrain[k]);
	}
	return 0;
}

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

C++: #include<bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く 
　　提出する問題を間違えない */
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
int main(){
  stack<int> train;
  int a;
  while(1){
    cin >> a;
    if(a){
      //if(cin.eof())break;
      train.push(a);
    }else{
      cout << train.top() << endl;
      train.pop();
      if(train.empty())break;
    }
  }
}

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

int main() {
	int a[10] = {0}, i = -1, n;
	while(cin >> n) {
		if(n == 0) {
			cout << a[i--] <<endl;
		} else{
			i++;
			a[i] = n;
		}
	}
	return 0;
}

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

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

using namespace std;

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

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cmath>
 
using namespace std;

int main(){
    int n;
    int stack[10] = {0};
    int index = 0;
    while(cin >> n){
        switch(n){
            case 0 : {
                index--;
                cout << stack[index] << endl;
                break;
            }
            default : {
                stack[index] = n;
                index++;
                break;
            }
        }
    }
    return 0;
}

C++: //include---------------------------------------------------------------------------
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cctype>
#include<ccomplex>
#include<vector>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<algorithm>


//using namespace-------------------------------------------------------------------
using namespace std;

//define,const----------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < n; i++){
const int INF = 1 << 25;

//global----------------------------------------------------------------------------
stack<int> cars;
int numbar;

//function--------------------------------------------------------------------------
int main(){
	while(scanf("%d", &numbar) != EOF){
		if(numbar == 0){
			printf("%d\n", cars.top());
			cars.pop();
			continue;
		}
		cars.push(numbar);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(void) {
  int num;
  stack<int> s;
  while(cin >> num) {
    if(num != 0) s.push(num);
    else { printf("%d\n", s.top()); s.pop(); }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

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

using namespace std;

int main()
{
	stack<int> s;

	vector<int> Ans;

	int temp;

	while (true)
	{
		cin >> temp;

		if (temp != 0)
		{
			s.push(temp);
		}
		else
		{
			Ans.push_back(s.top());

			s.pop();
		}

		if (s.empty())
		{
			break;
		}
	}

	for (vector<int>::size_type i = 0; i < Ans.size(); i++)
	{
		cout << Ans[i] << endl;
	}

	return 0;
}

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

int main() {
    vector<int> train;
    int n;
    while(cin >> n){
        if(n){
            train.push_back(n);
        }else{
            cout << train.back() << endl;
            train.pop_back();
        }
    }
    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();
		}else{
			break;
		}
	}

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

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>
using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	stack<int> s;
	s.push(n);
	
	int a;
	cin >> a;
	if(a == 0){
		cout << s.top() << endl;
		s.pop();
	}
	else {
		s.push(a);
	}
	
	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(){
	int tmp;
	stack<int>st;
	cin>>tmp;
	st.push(tmp);
	while(st.empty()==false){
		cin>>tmp;
		if(tmp>0){
			st.push(tmp);
		}
		else if(tmp==0){
		cout<<st.top()<<endl;
		st.pop();
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
int a[]={0,0,0,0,0,0,0,0,0,0};
int b;
while(cin>>b){
if(b==0){
cout<<a[0];
for(int i=0;i<9;i++){
a[i]=a[i+1];}}
else{
for(int i=0;i<9;i++){
a[9-i]=a[8-i];}
a[0]=b;}}

C++: #include <iostream>

using namespace std;

typedef struct Stack {
        int array[100];
        int top;

        Stack()
                :top(0)
        {
                for (int i = 0; i < 100; i++) {
                        array[i] = 0;
                }
        }
} Stack;

int main()
{
        Stack stack;
        int car;

        while (cin >> car) {
                if (car) {
                        stack.array[stack.top++] = car;
                } else {
                        printf("%d\n", stack.array[--stack.top]);
                        stack.array[stack.top] = 0;
                }
        }

        return 0;
}