Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	n, err := strconv.Atoi(nextString())
	return n, err
}

func main() {
	scanner.Split(bufio.ScanWords)

	stack := []int{}
	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		if n == 0 { // pop
			fmt.Println(stack[len(stack)-1])
			stack = stack[0:(len(stack) - 1)]
		} else { // push
			stack = append(stack, n)
		}
	}
}

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;
	}
}

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

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
	stack<int> s;
	int n;
	while(1) {
		if(scanf("%d", &n) == EOF) break;
		if(n > 0) {
			s.push(n);
		} else if(n == 0) {
			if(!s.empty()) {
				cout << s.top() << endl;
				s.pop();
			}
		}
	}
}

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

int main(){

	std::stack<int> train;
	int buf;

	while(std::cin >> buf){

		if(buf == 0){

			std::cout << train.top() << std::endl;
			train.pop();

		}else{
			train.push(buf);
		}
	}
	return 0;
}