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 <iostream>
#include <stack>

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

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

using namespace std;

void solve()
{
	stack<int> Stack;
	int num;
	while(cin >> num)
	{
		if(num == 0)
		{
			cout << Stack.top() << endl;
			Stack.pop();
		}
		else
		{
			Stack.push(num);
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

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

	while (cin >> a){

		if (a != 0){
			car.push(a);
		}
		if (a == 0){
			cout << car.top() << endl;
			car.pop();
		}
	}

	return 0;
}

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

int main()
{
	stack<int> car;
	vector<int> outlist;

	while( !car.empty() || outlist.empty() )
	{
		int carnum;
		if(!(cin >> carnum))
		{
			break;
		}
		if(carnum)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}
	
	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

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

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

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

int main() {
  int in;
  stack<int> t;

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

C++: #include<stdio.h>
const int SIZE=100;
int data[SIZE];
int sp=0;
int size(){
  return sp;
}
int empty(){
  return sp<=0;
}
int top(){
  return data[sp-1];
}
void pop(){
  sp--;
}
void push(int v){
  data[sp]=v;
  sp++;
}
int main(){
  int n;
  while(1){
    scanf("%d",&n);
    if(n==0){
      printf("%d\n",top());
      pop();
    }else{
      push(n);
    }
    if(empty())break;
  }
  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;		//入力される数（電車番号）を格納する
	int dummy = 0;				//ダミーナンバー

	while (std::cin >> dummy){
		if ((dummy == 0) && (!input.empty())){
			input.pop();
		}
		else if((1 <= dummy) && (dummy <= 9)){
			input.push(dummy);
		}
		else{
			//何もしない
		}
	}

	while (!input.empty()){
		std::cout << input.top() << std::endl;
		input.pop();
	}

	//while (1);
	return 0;
}

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

using namespace std;

template <typename Type>
struct print_endl : public unary_function < const Type&, void >
{
	void operator()(const Type& n)
	{
		cout << n << endl;
	}
};


int main()
{
	stack<int> s;

	vector<int> Ans;

	int temp;

	while (cin >> temp)
	{
		if (temp != 0)
		{
			s.push(temp);
		}
		else
		{
			Ans.push_back(s.top());

			s.pop();
		}

		if (s.empty())
		{
			break;
		}
	}

	for_each(Ans.begin(), Ans.end(), print_endl<int>());

	return 0;
}

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

int main() {
	int n;
	vector<int> vec;
	while (cin >> n) {
		if (n != 0) vec.push_back(n);
		else {
			cout << vec[vec.size() - 1] << endl;
			vec.pop_back();
		}
	}
	return 0;
}

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

int main(){
    stack<int> stk;
    int a;
    while(scanf("%d",&a) != EOF){
        if(a == 0){
            cout << stk.top() << endl;
            stk.pop();
        }else{
            stk.push(a);
        }
    }

    return 0;
}

C++: #include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void)
{
  stack <int> n;
  int a;

  while(scanf("%d", &a)!=EOF)
    {
      if(a==0)
	{
          cout<<n.top()<<endl;
          n.pop();
	}

      else
        n.push(a);
    }
}

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;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num == 0 && point > 0) pop();
		else push(num);
	}

    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>
#include <stack>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

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

  while(scanf("%d", &in) != EOF){
    if(in == 0){
      printf("%d\n",s.top());
      s.pop();
    }
    else s.push(in);
  }

  return 0;
}

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[202][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[201] = {0};
    bool judge = true;
    int tempjudge = 0;
    
    while(judge)
    {
        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 << "ouput"<< answer[l] << endl;
                    l++;
                    break;
                }
        }
        REP(k,i+1)
        if(a[k][1] != 1){
                judge = true;
                break;
        }
        else
            judge = false;
                
        
        i++;
    }

    return 0;
}

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

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

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

int main(){
	int car[100];
	int input;
	int i = 0;

	while(cin >> input){
		if(input == 0){
			i--;
			cout << car[i] << endl;
		}else{
			car[i] = input;
			i++;
		}
	}
}

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

C++: #include <stdio.h>

int main()
{
int p[10]={};
int x,i;
i=0;
while(scanf("%d",&x)!=EOF)
{
if(x==0){printf("%d\n",p[i]);i--;}
else if(x!=0){p[i]=x;i++;}
}
return 0;
}

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

using namespace std;

int main(void){
  int x;
  stack<int>st;

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

C++: #include <iostream>
#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;
}