Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Railway struct {
	trains trains
}

type trains []int

func main() {
	var stdin string
	var s = bufio.NewScanner(os.Stdin)

	railway := Railway{}
	for s.Scan() {
		stdin = s.Text()

		n, err := strconv.Atoi(stdin)
		if err != nil {
			continue
		}
		railway.lifo(n)
	}
}

func (r *Railway) lifo(n int) {
	if n == 0 {
		if len(r.trains) == 0 {
			return
		}
		fmt.Println(r.trains[len(r.trains)-1])
		r.trains = r.trains[:len(r.trains)-1]
	} else {
		r.trains = append(r.trains, n)
	}
}

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;
}

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;}