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 <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

using namespace std;

stack<int> st;
queue<int> qu;
int a;

int main()
{
	while(cin >> a, !cin.eof())
	{
		
		if( a == 0 )
		{
			qu.push(st.top());
			st.pop();
		}
		else
			st.push(a);
	}
	
	while(!qu.empty())
	{
		cout << qu.front() << endl;
		qu.pop();
	}
	
	return 0;
}

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

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

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

int main(){
	int n,a=0,b=0;
	vector <int> g;
	while(true){
		cin>>n;
		if(n!=0){
			g.push_back(n);
		}else{
			n=g.back();
			g.pop_back();
			cout<<n<<endl;
		}
	}
	return 0;
}

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

C++: #include <stdio.h>

#define BUF_SIZE 256

class stack10 {
private:
	int stack[10];
	int index;
public:
	stack10() {
		for (int i=0; i<10; i++)  stack[i]=0;
		index=0;
	}
	void PutTrain(int n) {
		if (index<10)  stack[index++] = n;
		else  printf("error: put\n");
	}
	int PopTrain() {
		if (index>0)  return stack[--index];
		else {
			printf("error: pop\n");
			return -1;
		}
	}
};

int main(void) {
	stack10 s;
	int i, j;
	int num;
	char buf[BUF_SIZE];
	
	while (fgets(buf, sizeof(buf), stdin) != NULL) {
		sscanf(buf, "%d", &num);
		
		if (num == 0)  printf("%d\n", s.PopTrain());
		else s.PutTrain(num);
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
void pop(int *i,int a){
	cout<<a<<endl;
	*i++;
}
void push(int *i,int *a,int n){
	*i++;
	*a=n;
}
int main(){
	int a[100],i,n,j,k,p;

	for(i=0;i<100;i++){
		a[i]=0;
	}
	i=0;
	while(cin>>n){
		if(n==0){
			pop(&i,a[i]);
		}else{
			push(&i,&a[i+1],n);
		}
		i;
	}

    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int> line;
	int pro;
	while(1)
	{
		cin>>pro;
		if(pro!=0){
			line.push_back(pro);
		}else{
			cout<<*(line.end()-1)<<endl;
			line.erase(line.end()-1);
		}
		if(line.empty())break;
	}
	return 0;
}

C++: #include <stdio.h>

int data[10];
int sp = 0;
int read;

int top()
{
 return data[sp-1];
}

void pop()
{
 sp--;
}

void push(int v)
{
 data[sp] = v;
 sp++;
}

int main()
{
 while(1)
 {
  scanf("%d",&read);
  if(read == 0)
  {
   printf("%d\n",top());
   pop();
  }
  else
  {
   push(read);
  }
 }
 return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(void)
{
    vector<int> t;
    int a;
    while (cin >> a)
    {
        if (a != 0)
        {
            t.push_back(a);
        }
        else if (a == 0)
        {
            cout << t.back() << endl;
            t.pop_back();
        }
    }
}

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

struct tCell{
	int value;
	tCell* prev;
	tCell* next;
};

class List{
public:
	List() : mQ( 0 ), head( NULL ), tail( NULL ){
		tail = new tCell;
		head = new tCell;
		tail->value = head->value = 0;
		head->prev = tail->next = NULL;
		head->next = tail;
		tail->prev = head;
	}
	~List(){
		for ( int i = mQ; i > 0; --i ){
			tCell* cell = tail->prev;
			tail->prev = cell->prev;
			delete cell;
		}
		if ( !head ) delete head;
		if ( !tail ) delete tail;
	};

	void push( int a ){
		++mQ;
		tCell* cell = new tCell;
		cell->value = a;
		cell->next = tail;
		cell->prev = tail->prev;
		tail->prev->next = cell;
		tail->prev = cell;
	}
	
	bool popStack( int& a ){
		if ( mQ == 0 ) return false;
		--mQ;
		a = tail->prev->value;
		tCell* cell = tail->prev;
		cell->prev->next = cell->next;
		cell->next->prev = cell->prev;
		delete cell;
		return true;
	}
	
	bool popQueue( int& a ){
		if ( mQ == 0 ) return false;
		--mQ;
		a = head->next->value;
		tCell* cell = head->next;
		cell->next->prev = cell->prev;
		cell->prev->next = cell->next;
		delete cell;
		return true;
	}

	int mQ;
	tCell *head, *tail;
private:
};

int main(){
	List list1;
	List list2;
	int a;
	
	while ( cin >> a ){
		list1.push( a );
	}

	while ( list1.popQueue( a ) ){
		if ( a ){
			list2.push( a );
		}else{
			list2.popStack( a );
			cout << a << endl;
		}
	}

	return 0;
}

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

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

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

int main()
{
  int line[100],train,k=0;

  while(cin>>train){
    if(train==0){
      k--;
      cout<<line[k]<<endl;
    }else{
      line[k]=train;
      k++;
    }
  }
}

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

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

int main() {
  stack<int> sta;
  
  while(1){
  
    int temp;
    cin >> temp;
    
    if (temp==0){
      if (sta.empty()){
	cout << sta.top() <<endl;
	sta.pop();
      }
    }else{
      sta.push(temp);
    }
  }
    
  return 0;
  
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main(){
	stack<int> st;
	for (int n; 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() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int train;
  stack<int> trains;

  while (cin >> train) {
    if (train == 0) {
      cout << trains.top() << endl;
      trains.pop();
    } else {
      trains.push(train);
    }
  }

  return 0;
}

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

int main() {
	vector<int>v;
	vector<int>::iterator pv=v.begin();
	int n;
	while (1) {
		cin >> n;
		if (n == EOF) { break; }
		if (n == 0) {
			pv = v.end();
			cout << *pv << endl;
			pv = v.begin();
			v.pop_back();
		}
		v.push_back(n);		
	}
	return 0;
}