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*****/
#include <iostream>
#include <fstream>
#include <list>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****変数置き場*****/
	list<int> V;
	int order;
	/*****処理部*****/
	while(1){
		cin >> order;
		if(order == 0){
			cout << V.back() << endl;
			V.pop_back();
		}else{
			V.push_back(order);
		}
	}
	return 0;
}

C++: #include<stdio.h>
const int SIZE=100;
int data[SIZE]={0};
int sp=0;
int size(){
  return sp;
}
int empty(){
  return sp<=0;
}
int isfull(){
  return sp>=SIZE;
}
int top(){
  return data[sp-1];
}
void pop(){
  sp--;
}
void push(int v){
  data[sp]=v;
  sp++;
}
int main(){
  int k,n;
  for(k=0;k<100;k++){
    scanf("%d",&n);
    if(empty()&&n==0)break;
    if(!empty()&&n==0){
      printf("%d\n",top());
      pop();
    }else if(!isfull()){
      push(n);
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int a[101],b[101];
int main()
{
	int i=1,j,n,s=1;
	bool yes;
	while(cin>>a[i])
	{
		if(a[i]==0)
		{
			j=i-1;
			yes=true;
			while(yes==true)
			{
				if(a[j]!=0)
				{
					b[s]=a[j];
					a[j]=0;
					s++;
					yes=false;
				}
				j--;
			}
		}
		i++;
	}
	for(i=1;i<s;i++)cout<<b[i]<<endl;
	return 0;
}

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

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

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

C++: #include<iostream>
int main(){
	int n,sp=0,st[10];
	while(std::cin>>n)
		if(n)st[sp++]=n;
		else std::cout<<st[--sp]<<std::endl;
	return 0;
}

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

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> a;
  queue<int> ans;
  int box;
  while(1){
    cin >> box;
    if(box){
      a.push(box);
    }else{
      ans.push(a.top());
      a.pop();
    }
    if(a.empty())break;
  }
  while(1){
    cout << ans.front() << endl;
    ans.pop();
    if(ans.empty())break;
  }
}

C++: #include <bits/stdc++.h>
using  namespace std;
#define ll    long long int
#define pai     pair<int,int>
#define vi      vector<int>
#define vd      vector<double>
#define mpi     map<int,int>
#define mps     map<string,int>
#define sti     stack<int>
#define stc     stack<char>
#define sei     set<int>
#define ses     set<string>
#define multii  multiset<int>

 int main()
{
sti s;
vi v;
ll x;
while(cin>>x){
if(x==0){
    v.push_back(s.top());
    s.pop();
}
else{
  s.push(x);
}
}
for(int i=0;i<v.size();i++){
   cout<<v[i]<<endl;
}

}

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

int
main(void)
{
	char line[80];
	int m;
	std::stack<int> s;

	while (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%d", &m) == 1) {
			if (m == 0) {
				printf("%d\n", s.top());
				s.pop();
			} else {
				s.push(m);
			}
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())

int main(int argc, char const *argv[])
{
	stack<int> st;
	int i;
	while(scanf("%d", &i) != EOF)
	{
		if (i == 0)
		{
			printf("%d\n", st.top());
			st.pop();
		}
		else
		{
			st.push(i);
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int i=0,num,a[10],x=0;
  
  while(cin>>num){
    if(num==0){
      cout<<a[i-1]<<endl;
      i--;
    }
    else  a[i++]=num;
    if(!i)break;
  }
  
    return 0;
}

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

using namespace std;

int main(void){
	int num;
	stack<int> train;

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

	return 0;
}

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

int main() {

	std::stack<int> st;
	int inp;//input

	while (std::cin >> inp)
	{
		if (inp == 0) {//output data and pop data
			std::cout << st.top() << std::endl;
			st.pop();
		}
		else {//push data
			st.push(inp);
		}
	}

	return 0;
}

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

int main()
{
	int x;
	int stack[N];
	int n = 0;
	
	while (cin >> x) {
		if (x != 0) {
			stack[n] = x;
			n++;
		} else {
			cout << stack[n - 1] << "\n";
			n--;
		}
	}
	return 0;
}

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

int main()
{
	stack<int> train ;
	int i ;

	while( cin >> i )
	{
		if( i != 0 )
		{
			train.push(i) ;
		}
		else
		{
			cout << train.top() << "\n" ;
			train.pop() ;
		}
	}
	return 0 ;
}

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

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();
			stack.pop_back();
			continue;
		}
		// ???????????????????????°????????\??????
		stack.push_back(num);
	}
	return 0;
}

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

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

    int n;
    std::stack<long long int> s;

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

    return 0;
}

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

using namespace std;

int main() {
	int b;
	int a[10] = {0};

	while (cin >> b) {
		if (b == 0) {
			for (int i = 9; i >= 0; i--) {
				if (a[i] != 0) {
					cout << a[i] << endl;
					a[i] = 0;
					break;
				}
			}
		} else {
			for (int i = 0; i < 10; i++) {
				if (a[i] == 0) {
					a[i] = b;
					break;
				}
			}
		}
	}
	return 0;
}

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

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

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

int main() {
	int n, count = 0, a[10], i;
	stack<int> s;
	while (cin >> n,n>=0,!cin.eof()) {
		if (n > 0) s.push(n);
		else if (n == 0) { a[count] = s.top(); s.pop(); count++}
	}
	for (i = 0; i < count; i++) {
		cout << a[i] << endl;
	}
}