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



int main(){

	vector <int> num_array;
	int car_num;
	size_t size();
	while (cin >> car_num){
	
		if (car_num != 0){
			num_array.push_back(car_num);
		}
		else if (car_num == 0){
			cout << num_array[num_array.size() - 1] << endl;
			num_array.pop_back();
		
		}
	}

	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(void){
    int car;
    stack <int> s;
    while(cin >> car){
        if(car != 0)
            s.push(car); //要素を挿入する
        else{
            cout << s.top() << endl; //一番上の要素を参照し、その要素を出力する
            s.pop(); //一番上の要素を削除する
        }
    }
}

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

using namespace std;

stack<int> s;
int ac;

int main(void) {
    freopen("i.in", "r", stdin);
    while(~scanf("%d", &ac)) {
        if(ac == 0) {
            cout << s.top() << endl;
            s.pop();
        } else {
            s.push(ac);
        }
    }
    return 0;
}

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

using namespace std;

int main()
{
	stack<int> trains;
	queue<int> aparted;
	int n, c, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &c);
		if (c == 0)
		{
			aparted.push(trains.top());
			trains.pop();
		}
		else
			trains.push(c);
	}
	while (aparted.empty()!=true)
	{
		printf("%d\n", aparted.front());
		aparted.pop();
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

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

C++: #include<iostream>
using namespace std;
int main(){
  
  int a[10],b[10],c=0,d=0,num;

  while(1){

    cin >>num;

    if(num >= 1 && num <=10){
      a[c]=num;
      c++;
    }else if(num == 0){
      b[d]=a[c-1];
      c--;
      d++;
    }

    if( c == 0 )break;

  }

  for(int i=0 ; i < d ; i++){
    cout <<b[i]<<endl;
  }

  return 0;
}

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

C++: #include <bits/stdc++.h>
using namespace std;

int main()
{
	int val;
	vector<int> st;
	while (cin >> val) {
		if (val) {
			st.push_back(val);
		}
		else {
			cout << st.back() << endl;
			st.pop_back();
		}
	}
	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>
using namespace std;

int main(void){
     int n[100];
     int i=0;
     int d;
     while(cin >> d,!cin.eof()){
	  
	  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;
     }

     return 0;
}

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

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

C++: /*
NOTE :
*min_element(.begin(),.end())
*max_element(.begin(),.end())
stack push pop top
queue push pop front
priority_queue<> pq
 push()  pop() size()  top()
map<>
 find() begin() end() insert(map<>::value_type())
pair<>
sort(.begin(), .end())
sort(arr, arr+N)
sort(a, a+N, greater<int>())
binary_search(vc.begin(), vc.end(), x)  //binary_search???true, false?????????
vector<int>::iterator lit = lower_bound(vc.begin(), vc.end(), x);
  lower_bound?????????????????????"??\???"????????????????????????????????????????????¬???????????????
vector<int>::iterator uit = upper_bound(vc.begin(), vc.end(), x);
  upper_bound????????????????????????"?¶???????"?????????????????????????????????????????¬???????????????
*/
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <valarray>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

#define MAX 100
#define INF 1<<20
#define LLINF 10e12 // 1<<31 // 2^31
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,a,n) for(int i=(a);i<(n);i++)
#define SET(a,c) memset(a,c,sizeof a)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique(ALL((o))), (o).end());

using namespace std;
typedef long long ll;
typedef valarray<int> array_t;
/////

/////
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // FROM HERE
  int n;
  stack<int> T;
  vector<int> V;
  while (cin >> n)
  {
    if(n == 0)
    {
      V.push_back(T.top());
      T.pop();
    }
    else T.push(n);
  }
  FOR(a,V) cout << *a << endl;
  return 0;
}

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

using namespace std;

template <typename Type>
struct print_endl : public unary_function < const Type&, void >
{
	void operator()(const Type& n)
	{
		cout << n << endl;
	}
};


int main()
{
	stack<int> s;

	vector<int> Ans;

	int temp;

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

			s.pop();
		}
	}

	for_each(Ans.begin(), Ans.end(), print_endl<int>());

	return 0;
}

C++: #include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#define INF 100000000
 
using namespace std;
typedef long long ll;

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

C++: #include <stdio.h>

class stack
{
private:
	int rail[10];
	int nowRail;
public:
	stack( void );
	void add( int number );
	int gone( void );
};

stack::stack( void )
{
	nowRail = 0;
}

void stack::add( int number )
{
	rail[nowRail] = number;
	nowRail++;
}

int stack::gone( void )
{
	nowRail--;
	return (rail[nowRail]);
}

int main( void )
{
	int number;
	stack* Stack = new stack();
	
	while( scanf( "%d", &number ) != EOF )
	{
		if( number == 0 )
		{
			printf( "%d\n", Stack->gone() );
		}
		else
		{
			Stack->add( number );
		}
	}
	
	return (0);
}

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

int main()
{
	int n=0;
	vector<int>a;

while(cin>>n)
{

if(n==0)
	{
		cout<<a.back()<<endl;
		a.pop_back();
	}
	else
	{
		a.push_back(n);
	}
	
}

	
return 0;
}

C++: #include<stdio.h>
int i=0;
int cars[19];

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

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

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

using namespace std;

int n;
int a[10];
int i = 0;

int main(void)
{
	stack<int> s;
	while(scanf("%d", &n) != EOF){
		if(n == 0){
			a[i] = s.top();
			s.pop();
			i++;
		}
		else{
			s.push(n);
		}
	}
	
	for(int j = 0; j < i; j++){
		printf("%d\n", a[j]);
	}
	
	return 0;
}