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

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

using namespace std;

int main()
{
	vector<int> train;
	int a;
	vector<int>::iterator it;
	for(;cin >> a;)
	{
		if(a!=0)
			train.push_back(a);
		else
		{
			it=train.end()-1;
			cout << *it << endl;
			train.pop_back();
		}
	}
}

C++: #include<stdio.h>
int main(){
int a[100];
int j,a=0;
for(int i=0;i<100;i++){
scanf("%d",&a[i]);
if(a[i]==0){
j=i;
while(a=0){
if(j-1!=0){
printf("%d",a[j-1]);
a=1;
}
j--;
}
a=0;
a[j]=0;
if(j-1==0){
i=101;
}
}
}

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

int main(){
	int in[10],out[10];
	int in_num=0;
	int out_num=0;
	int n;
	while(cin >>n){
		if(n == 0){
			in_num--;
			out[out_num] = in[in_num];
			out_num++;
		}
		else {
			in[in_num] = n;
			in_num++;
		}
	}
	for(int i=0;i<out_num;i++)
		cout <<out[i]<<endl;
		
	return 0;
}

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

int main(){

    int c;
    stack<int> s;
    while(scanf("%d", &c) != EOF) {
        if (c == 0 && !s.empty()) { printf("%d\n", s.top()); s.pop(); }
        else if (c > 0) s.push(c);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    int a,i;
    vector<int> s;
    vector<int> t;
    while(cin>>a){
        if(a!=0){
            s.push_back(a);
        }else{
            s.pop_back();
            t.push_back(s[s.size()-1]);
            s.pop_back();
        }
    }
    int b=t.size();
    for(i=0;i<b;i++){
        cout << t[i] << endl;
    }
    return 0;
}

C++: #include <stdio.h>

#define N 10
int main(void){
    int stk[N], sp=0;
    int n;
   
    for (int i=0; i<N; i++) stk[i]=0;
    while (scanf("%d", &n)){
        if (n==0){
	    printf("%d\n", stk[--sp]);
	} else {
	    stk[sp++] = n;
	}
    }
    return 0;
}

C++: #include<stdio.h>
 
 
int main(void)
{
    int num, top;
    int train[1024];
    int i;
 
    top = 0;
 
    while (scanf("%d", &num) != EOF){
        if (num == 0){
            printf("%d\n", train[top - 1]);
            train[top - 1] = 0;
            top--;
        }
        else {
            train[top] = num;
            top++;
        }
    }
 
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> a;
  int box;
  while(1){
    cin >> box;
    if(box){
      a.push(box);
    }else{
      cout << a.top() << endl;
      a.pop();
    }
    if(cin.eof())break;
  }
}

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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>
#include <stack>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int in;
  stack<int> s;

  while(scanf("%d", &in) != EOF){
    if(in == 0){
      printf("%d\n",s.top());
      s.pop();
    }
    else s.push(in);
  }

  return 0;
}

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

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