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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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>

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 long long LL;
typedef unsigned long long ULL;

//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
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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


  while(cin >> n) {
    if(!n) {
      cout << s.top() << endl;
      s.pop();
    }
    else s.push(n);
  }
}

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

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;
typedef vector<long long int> vi;
typedef vector<long long int>::iterator vit;

int main(){
	int n, k;
	vector<int> vi, vi2;
	while (cin >> n)
	{
		if (n == 0){
			vi.pop_back();
			vi2.push_back(k);
		}
		else {
			vi.push_back(n);
		}
		k = vi[vi.size() - 1];
	}
	REP(i, vi2.size()){
		cout << vi2[i] << endl;
	}
}

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

int main () {

int a[20]={0}, b[20]={0}, k = 0;
int train = 0, zero = 0;

    for (int i = 0; i < 20; i++){
        cin >> a[i];

    if (a[i] != 0)
        train++;
        else zero++;

    if (train == zero)
        i=100;

    }


    for (int j = 1; j < 20; j++){


            if (a[j-1] != 0 && a[j] == 0){
                b[k] = a[j-1];
                k++;

                for (int count = j; count < 19; count++)
                a[count-1] = a[count+1];

                j = 0;

            }

        }

    for (int n = 0; n < 20; n++) {
        if (b[n] != 0)
        cout << b[n] << endl;

    }

    return 0;

}

C++: #include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int a;
    stack<int> s;
    while(cin >> a){
        if(a)s.push(a);
        else{
            cout << s.top() << endl;
            s.pop();
        }
    }
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int x[1000] ={0},y[1000] = {0};
    int n;
    int a = 0,b = 0;

    while(scanf("%d",&n)!=EOF){
        if(n == 0){
            x[a] = y[b-1];
            b--;
            ++a;
        }
        else {
            y[b] = n;
            b++;
        }
    }
    for(int i = 0;i < a; i++)printf("%d\n",x[i]);

    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 <iostream>
#include <stack>
using namespace std;

int main( void )
{
	stack <int> S;
	int first;
	cin >> first;
	S.push( first );

	while ( S.empty() == false )
	{
		int n;
		cin >> n;
		if ( n == 0 )
		{
			cout << S.top() << endl;
			S.pop();
		}
		else
		{
			S.push( n );
		}
	}

	return 0;
}

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

using namespace std;

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

C++: #include<iostream>
#include<stack>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

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

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#define mp make_pair
#define pii pair<int,int> 
#define ff first
#define ss second

using namespace std;

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

C++: #include<iostream>

using namespace std;

int main() {
	int train[11] = { 0 }, junban[11] = { 0 }, a = 0, n, i;
	while (cin >> n) {
		if (n == 0) {
			for (i = 0; train[i] > 0; i++) {}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; train[i] > 0; i++) {}
			train[i] = n;
		}
	}
	for (i = 0; junban[i] > 0; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}

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

int main(){
	int n;
	int temp;
	stack<int> data;
	
	while(1){
		scanf("%d",&n);
		
		if(n!=0){
			data.push(n);
		}
		else{
			if(data.empty() == true)break;
			else{
				printf("%d\n",data.top());
				data.pop();
			}
		}
	}
	return 0;
}

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

int main(){
	int a[100];
	int i = 0;

	while (1){
		cin >> a[i];
		if (a[i] == 0){
			int j = i + 1;
			while (1){
				j--;
				if (a[j] != 0){
					cout << a[j] << endl;
					a[j] = 0;
					break;
				}
			}
		}
		i++;
	}


	return 0;
}

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

int main(){
	int n;
	stack<int> stk;
	queue<int> que;
	while(1){
		cin>>n;
		if(n==0){
			que.push(stk.top());
			stk.pop();
		}else{
			stk.push(n);
		}
		if(stk.empty())break;
	}
	while(!que.empty()){
		cout<<que.front()<<endl;
		que.pop();
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <stack>
using namespace std;
int main(){
  int n;
  stack<int> in,out;
  while(cin>>n){
    if(!n)out.push(in.top()),in.pop(),cout<<out.top()<<endl;
    else{in.push(n);}
    if(!in.size()&&out.size()>0)return 0;
  }
}