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<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	stack<int>p;
	stack<int>s;
	int n;
	
	while (cin >> n) {
		if (n == 0) {
			s.push(p.top());
			cout << s.top() << endl;
			p.pop();
		}
		else {
			p.push(n);
		}
	}
	
	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;
	while(1){
		int n;
		if(!(cin>>n))break;
		if(n==0){
			
			cout<<st.top()<<endl;
			st.pop();
		}
		else{
			st.push(n);
		}
	}
	return 0;
}

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

int main(){
    std::stack<int> rail;
    int buf;
    
    // repeat until "cin" fails.
    while (std::cin >> buf) {
        if (buf == 0) { // train goes out.
            std::cout << rail.top() << std::endl;
            rail.pop();
        }
        else{   // train comes in.
            rail.push(buf);
        }
    }
    
    return 0;
}

C++: #include<stdio.h>
#include<stack>
using namespace std;
int main(){
	stack<int>cars;
	int i;
	while(~scanf("%d",&i)){
		if(i==0){
			printf("%d\n",cars.top());
			cars.pop();}
		else cars.push(i);}
	return 0;}

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

using namespace std;

int main(){
    int num;
    stack <int> s;
    while(1){
        cin >> num;
        if(!num){
            if (s.empty()) break;
            cout << s.top() <<endl;
            s.pop();
        }
        else s.push(num);
    }
    return 0;
}

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

int main() {
	vector<int> v(10);
	int n, j = 0;
	while (cin >> n) {
		if (n) {
			v.at(j) = n;
			j++;
		}
		else {
			j--;
			cout << v.at(j) << endl;
			v.at(j) = 0;
		}
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
	int a[10], num;
	int count = 0;

	while(cin >> num){
		if(num != 0){
			a[count] = num;
			count++;
		}
		else{
			cout << a[count - 1] << endl;
			count--;
		}
	}

	return 0;
}

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

int main(){
	stack<int> st;
	int n, a;

	while(cin >> n){
		if(n!=0){
			st.push( n );
		}else{
			a = st.top();
			cout << a << endl;
			st.pop();
		}
	}
}

C++: #include <stdio.h>

int main() {
	int a,i,k,m;
	int data[15] = {0};
	int output[15] = {0};
	for (i = 0; i < 15; i++) {
		scanf("%d", &a);
		if (a != 0) {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					data[k] = a;
					break;
				}
			}
		}
		else {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					for (m = 0; m < 15; m++) {
						if (output[m] == 0) {
							output[m] = data[k - 1];
							break;
						}
					}
					data[k - 1] = 0;
					break;
				}
			}
		}
	}
	for (i = 0; i < 15; i++) {
		if (output[i] != 0) {
			printf("%d\n", output[i]);
		}
	}
	return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const double EPS = 1e-12;
const double INF = 1e12;


int main(){
	int n;
	stack<int>st;
	vector<int>res;
	while(cin>>n){
		if(n!=0)st.push(n);
		else{
			res.PB(st.top());
			st.pop();
		}
	}
	REP(i,SZ(res))cout<<res[i]<<endl;
	return 0;
}

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

int main()
{
	stack<int> car;
	vector<int> outlist;
	int carnum;

	while( cin >> carnum )
	{
		if(carnum)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}

	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

C++: #include<iostream>
#include<string>
#include <stdio.h>
#include <math.h>
#include <cctype>
#include<queue>
#include<stack>
using namespace std;
stack<int> st;
int main(){
	int a;
	while(cin>>a){
		if(a!=0){
			st.push(a);
		}
		else{
			cout<<st.top()<<endl;
			st.pop();
		}
	}
	return 0;

}

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

using namespace std;

int main(){
	stack <int> depot;

	int train;

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

	return 0;

}

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

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int in;
	vector <int> a;
	while (1) {
		cin >> in;
		if (in == 0) {
			cout << a[a.size() - 1] << endl;
			a.erase(a.end() - 1);
			if (a.size() == 0)
				break;
		}
		else
			a.push_back(in);
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define PUSH intStackPush
#define POP intStackPop
#define TOP intStackTop
#define FREE intStackFree

typedef struct stack{ int data; struct stack* next; }stack;

stack *top = NULL;

stack* makeNewStack(int data){
  stack *new = (stack*)malloc(sizeof(stack));
  new->data = data;
  new->next = NULL;
  return new;
}

void intStackPush(int data){
  stack *new = makeNewStack(data);
  if(top != NULL){ new->next = top; top = new; }
  else top = new;
}

void intStackPop(){
  stack *temp;
  temp = top;
  top = top->next;
  free(temp);
}

int intStackTop(){ return top->data;}

void intStackFree(){ while(top != NULL) intStackPop();}

int main(){
  int in;

  while(scanf("%d", &in) != EOF){
    if(in == 0){
      printf("%d\n",TOP());
      POP();
    }
    else PUSH(in);
  }

  FREE();
  return 0;
}