Go: package main

import (
        "fmt"
)

func main() {
        var stk [101]int
        var c int
        pvt := 0
        for {
                _, err := fmt.Scanf("%d", &c)
                if err != nil {
                        break
                }
                if c > 0 {
                        stk[pvt] = c
                        pvt++
                } else {
                        pvt--
                        fmt.Printf("%d\n", stk[pvt])
                }
        }
}

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];
			a.erase(a.end() - 1);
			if (a.size() == 0) {
				cout << endl;
				break;
			}
			else
				cout << endl;
		}
		else
			a.push_back(in);
	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int main(){
	int k;
	stack<int> q;

	cin >> k;
	q.push(k);

	while (1){
		cin >> k;
		if (k != 0)
			q.push(k);
		else{
			printf("%d\n", q.top());
			q.pop();
		}
		if (q.empty())
			break;
	}
}

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

int main(){
	stack<int> st;
	queue<int> q;
	int input;

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

}

C++: #include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main(void)
{
  stack<int> in;
  queue<int> out;
  int n,c;
  cin>>c;
  in.push(c);
  while(!in.empty())
  {
    cin>>c;
    if(c==0){
      out.push(in.top());in.pop();
    }else{
      in.push(c);
    }
  }
  while(!out.empty())
  {
    cout<<out.front()<<endl;
    out.pop();
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.SRC", "r", stdin );
	string str = "";
	stack<int> st;
	while (getline (cin, str ) ){
		stringstream ss (str );
		int car = -1;
		ss >> car;
		if (car != 0 ){
			st.push (car );
		}else{
			cout << st.top() << endl;
			st.pop();
		} // end if
	} // end while
		
	return 0;
}

C++: #include <cstdio>
#include <stack>
using namespace std;
int main() {
	int n;
	stack<int> S;
	while(scanf("%d",&n)!=EOF) {
		if(n)S.push(n);
		else {
			printf("%d\n",S.top());
			S.pop();
		}
	}
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

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

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

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

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

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<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 <stdio.h>
#include <stack>
int main(void)
{
    using namespace std;
    stack<int> stk;
    int n;
    while(scanf("%d",&n)==1)
    {
        if(!n)
        {
            printf("%d\n",stk.top());
            stk.pop();
        }
        else
        {
            stk.push(n);
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
    stack<int> st;

    int a;

    cin >> a;
    st.push(a);

    while (st.size()) {
        cin >> a;
        if (a) st.push(a);
        else { cout << st.top() << endl; st.pop(); }
    }
}

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

int a[11], b, t;

int main() {
  cin>>a[0];
  t=1;
  
  while(cin>>b) {
    if(b>0) {
      a[t]=b;
      t++;
    }else {
      cout<<a[t-1]<<endl;
      t--;
    }
  }
  
  return 0;
}

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

C++: #include <cstdio>

int stack[10] = { -1 };
int size = 0;

void add(int n){
    stack[size] = n;
    size++;
}

void dec(){
    size--;
    printf("%d\n", stack[size]);
    stack[size] = -1;
}

int main(){
    int n;
    
    scanf("%d", &n);
    add(n);
    while(size != 0){
        scanf("%d", &n);
        if(n == 0){
            dec();
        }else {
            add(n);
        }
    }

    return 0;
}