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 <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	stack<int> S;
	int n;
	while ( cin >> n ) {
		if (n == 0) {
			cout << S.top() << endl;
			S.pop();
		}
		else {
			S.push(n);
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void)
{
    int a[250][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[220] = {0};
    bool judge = true;
    int tempjudge = 0;
    
    while(cin >> a[i][0])
    {
        if(a[i][0] == 0)
        {
            a[i][1] = 1;
            RFOR(j,i,-1)
            if(a[j][1] != 1 )
            {
                answer[l] = a[j][0];
                a[j][1] = 1;
                cout << answer[l] << endl;
                l++;
                break;
            }
        }
        
        i++;
    }
    
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <math.h>
#include <string>
#include <cmath>
#include <iomanip>

int main();


int main(){
	std::stack<int> input;		//入力される数（車両番号）を格納する
	std::vector<int> output;	//出力される車両番号
	int dummy = 0;				//ダミーナンバー
	int count = 0;

	while (count < 8){
		std::cin >> dummy;
		count++;
	//while (std::cin >> dummy){
		if ((dummy == 0) && (!input.empty())){
			output.push_back(input.top());
			input.pop();
		}
		else if((1 <= dummy) && (dummy <= 10)){
			input.push(dummy);
		}
		else{
			//何もしない
		}
	}

	for (int i = 0; i < output.size(); i++){
		std::cout << output[i] << std::endl;
	}

	//while (1);
	return 0;
}

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

int main() {
	int a[10] = {0}, i = -1, n;
	while(cin >> n) {
		if(n == 0) {
			cout << a[i--] <<endl;
		} else{
			i++;
			a[i] = n;
		}
	}
	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(){
	--point;
	std::cout << stack[point] << std::endl;
}

int main(){
	int num;

	while(std::cin >> num){
		if(num == 0 && point > 0) pop();
		else if(0 < num && num <= 10) push(num);
	}

    return 0;
}

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

int main(void)
{
	stack<int> car;

	do {
		int n;
		cin >> n;

		if(n > 0)
			car.push(n);

		if(n == 0) {
			cout << car.top() << endl;
			car.pop();
		}
	}while(car.empty() == false);

	return 0;
}

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

int main()
{
	int n;
	int cnt = 0;
	stack<int> car;
	vector<int> out;

	while (cin >> n, cin.eof() != true){
		if (n == 0){
			out.push_back(1);
			out[cnt] = car.top(); // top pop
			car.pop();
			cnt++;
		}
		else {
			car.push(n);
		}
	}

	for (int i = 0; i < cnt; i++){
		cout << out[i] << endl;
	}

	return (0);
}

C++: #include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;
int main(){
  int train[10],n,i;
  n = 0;
  int order[100],intrain[10];
  for( i = 1;i <= 10;i++){
    train[i] = i;
  }
  for(i=0;i<100;i++)
    order[i] = 11;
  i = 0;
  while(scanf("%d",&order[i]) != EOF){i++;}
  for(i = 0;order[i] != 11;i++){
    if(order[i] != 0){
      intrain[n] = order[i]; n++;}else if(order[i] == 0){
      n--;      cout << intrain[n] << endl;}
  }
}

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;
				}
			}
		}
		if (data[0] == 0) {
			break;
		}
	}
	printf("\n");
	for (i = 0; i < 15; i++) {
		if (output[i] != 0) {
			printf("%d\n", output[i]);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int main(){
    stack<int> s;
    int n, ans[100], ct = 0;
    while (cin>>n){
        if (n == 0) {
            ans[ct] = s.top();
            //cout << s.top() << endl;
            s.pop();
            ct++;
        } else {
            s.push(n);
        }
    }
    REP(i, ct){
        cout << ans[i] << endl;
    }
}

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

using namespace std;

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

C++: #include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	stack<int> st;
	queue<int> ans;

	int v;
	while (cin >> v) {
		if (v == 0) {
			ans.push(st.top());
			st.pop();
		} else {
			st.push(v);
		}
	}

	if (ans.empty()) {
		cout << 0 << endl;
	} else {
		while (!ans.empty()) {
			cout << ans.front() << endl;
			ans.pop();
		}
	}
	return 0;
}

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

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