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

int main(){
	std::stack<int> st;

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

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

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

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

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num==0) pop();
		else push(num);
	}

    return 0;
}

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

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

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int now=-1;//0ツガツキツつスツづつォツづ可偲ヲツづィツ出ツつキツづ猟つォツ配ツ療ア
	int n[10]={0};
	int in;
	//for(;;){
		while(cin>>in){
		if(in==0){
			cout<<n[now];
			now--;
			if(now==-1)return 0;
		}
		else{
			n[now+1]=in;
			now++;
		}
	}
}

C++: #include<cstdio>
#include<stack>
#include<iostream>
int main()
{
  using namespace std;
  int input;
  stack<int> st;
  while(~scanf("%d",&input))
    {
      if(input == 0)
        {
          cout<<st.top()<<endl;
          st.pop();
        }else
        {
          st.push(input);
        }
    }
  return 0;
}

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

using namespace std;


int main (int argc, char const* argv[]){
    stack<int> st;
    int n;
    int tmp;
    list<int> list1;
    
    while((cin >> n)){
        if(n == 0){ 
            list1.push_back(st.top());
            st.pop();
        }
        else st.push(n);
    }
    
    list<int>::iterator it = list1.begin();
    while(it != list1.end()){
        cout << *it << endl;
        it++;
    }
    
    return 0;
}

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

int main(){
	int in;
	stack<int> st;
	while (cin >> in, !cin.eof()){
		if (in != 0)	st.push(in);
		else{
			cout << st.top() << endl;
			st.pop();
		}
	}
}

C++:  /*
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.

We can simulate the movement (comings and goings) of the cars as follow:

An entry of a car is represented by its number.
An exit of a car is represented by 0
For example, a sequence

1 6 0 8 10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.

Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
 */
 
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	vector<int> cars, ans, done(100000, -1);
	int temp, i=0, m;
	while (cin >> temp) {
		if (temp != 0) {
			cars.push_back(temp);
			i++;
		} else {
			sort(done.begin(), done.end());
			if (!binary_search(done.begin(), done.end(), cars.at(i-1))) {
				ans.push_back(cars.at(i-1));
				done.push_back(i-1);
			}
		}
	}
	for (int j=0; j<ans.size(); j++)
		cout << ans[j] << endl;
	return 0;
}

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

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num==0 && point>=0) pop();
		else push(num);
	}

    return 0;
}

C++: /*****include*****/
#include <iostream>
#include <fstream>
#include <list>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	list<int> V;
	int order;
	/*****処理部*****/
	while(1){
		cin >> order;
		if(order == 0){
			cout << V.back() << endl;
			V.pop_back();
		}else{
			V.push_back(order);
		}
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

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

int main(){
	int a[100];
	int i = 0;
	while (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>
#include <vector>
using namespace std;

int main(){
	vector<int> v;
	stack<int> s;
	int n;
	cin >> n;
	s.push(n);
	while(cin>>n){
		if(n==0){
			v.push_back(s.top());
			s.pop();
		} else {
			s.push(n);
		}
	}
	for(int i=0 ; i<v.size(); i++){
		cout << v[i] << endl;
	}
	return 0;	
}

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

int main() {
	vector<int> car;
	int n;
	
	while ( cin >> n ) {
		if ( n ) {
			car.push_back ( n );
		} else {
			cout << car.back () << endl;
			car.pop_back ();
		}
	}
	
	return 0;
}

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

using namespace std;

stack<int> s;
int ac;

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

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

int data;
stack<int> st;

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

  return 0;
}