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 "bits/stdc++.h"
using namespace std;

long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}
long long int lca(long long int l, long long int r) {
	return l / gcd(l, r)*r;
}
int getans(const int num, const int rest) {
	if (rest) {
		int ans = 0;
		for (int i = 0; i <= 9; ++i) {
			if (num >= i) {
				ans += getans(num - i, rest - 1);
			}
		}
		return ans;
	}
	else {
		return num == 0;
	}
}
int main() {
	int N;
	stack<int>sta;
	while (cin >> N) {
		
		if (N) {
			sta.emplace(N);
		}
		else {
			cout << sta.top() << endl;
			sta.pop();
		}
	}
	return 0;
}

C++: #include <stdio.h>

int train[10];
int sp = 0;

int empty() {
  return sp <= 0;
}

int size() {
  return sp;
}

int top() {
  return train[sp-1];
}

void pop() {
  sp--;
}

void push(int v) {
  train[sp] = v;
  sp++;
}

int main(){
  int num;
  while(1){
    scanf("%d", &num);
    if(num == 0){
      printf("%d\n", top());
      pop();
    }else if(1 <= num && num <= 10){
      push(num);
    }
    if(size() == 0) break;
  }
  return 0;
}

C++: #include<stdio.h>

int main(){
  int i = 0, x, count = 0;
  int data[100];
  while(count < 0){
    scanf("%d\n", x);
    data[i] = x;
    if(x == 0){
      count--;
      i--;
      if(count >= 0){
        printf("%d\n", data[i-1]);
      }
    }else{
      count++;
      i++;
    }
  }
  return 0;
}

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

int main(){
stack<int>a;
int b;
scanf("%d",&b);
a.push(b);
while(a.size()){
	scanf("%d",&b);
	if(b)a.push(b);
	else {printf("%d\n",a.top());a.pop();}
}
}

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

using namespace std;

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int i;
	int box[51];
	i=-1;
	while(1){
		//cout<<i<<endl;
		cin>>n;
		if(cin.eof())	break;
		if(n==0){
			cout<<box[i]<<endl;
			i--;
		}
		else{
			i++;
			box[i]=n;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int train;
  stack<int> stay;
  while(cin>>train){
    if(train==0){
      cout<<stay.top()<<endl;
      stay.pop();
    }else
    stay.push(train);
  }
  return 0;
}

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 <cstdio>

using namespace std;

int main()
{
	int num, tmp[10] = {0}, num_out[100] = {0};
	int cnt_1 = 9, cnt_2 = 0;
	
	while (scanf("%d", &num) != EOF){
		if (num == 0){
			num_out[cnt_2] = tmp[cnt_1 + 1];
			//printf("num_out[%d]=%d\n", cnt_2, num_out[cnt_2]);
			cnt_2++;
			cnt_1++;
		}
		else {
			tmp[cnt_1] = num;
			//printf("tmp[%d]=%d\n", cnt_1, tmp[cnt_1]);
			cnt_1--;
		}
	}
	
	for (int i = 0; i < 100; i++){
		if (num_out[i] != 0){
			printf("%d\n", num_out[i]);
		}
	}
	
	return (0);
}

C++: #include<bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く 
　　提出する問題を間違えない */
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
int main(){
  stack<int> train;
  int a;
  while(1){
    cin >> a;
    if(a != 0){
      if(cin.eof())break;
      train.push(a);
    }else{
      cout << train.top() << endl;
      train.pop();
    }
  }
}

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

using namespace std;

stack<int> s;
int ac;

int main(void) {
    while(~scanf("%d", &ac)) {
        if(ac == 0) {
            cout << s.top() << endl;
            s.pop();
        } else {
            s.push(ac);
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-6;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    int n;
    queue<int> q;
    while(cin>>n){
        if(n==0){
            cout<<q.front()<<endl;
            q.pop();
        }else{
            q.push(n);
        }
    }
}

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

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

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

C++: /*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <iostream> // ?¨??????\??????
#include <fstream>  // ??????????????\??????
#include <string>   // ???????????¢???
#include <vector>   // ???????????????
#include <cmath>    // ??°??????
#include <iomanip>  // stream???????????¢???
#include <algorithm>// max??¢??°??????

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;        // ????´???°????????????????????????
using std::fixed;         // ???????????????????¨???????????????????????????????
using std::setprecision;  // ?????°????°???°?????\???????????°????????????????????¨????????\???

int main() {
	int num;
	vector<int> stack;
	while (cin >> num)
	{
		if (num == 0)
		{
			// ??????????????????????????????????¶????
			cout << stack.back() << endl;
			stack.pop_back();
			continue;
		}
		// ???????????????????????°????????\??????
		stack.push_back(num);
	}
	return 0;
}

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

int main(){
	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 <stack>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]){
    int input; 
    stack<int> train_stack;
    vector<int> order;

    cin>>input;
    train_stack.push(input);
    while (!train_stack.empty()){
        cin>>input;
        if (input==0){
            order.push_back(train_stack.top());
            train_stack.pop();
        }
        else{
            train_stack.push(input);
        }
    }

    for (const auto& tarin_num : order){
        cout<<tarin_num<<endl;
    }
    
    return 0;
}

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

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