Go: package main

import (
        "fmt"
)

func main() {
        var stk [101]int
        var c int
        pvt := 0
        for {
                _, err := fmt.Scanf("%d", &c)
                if err != nil {
                        break
                }
                if c > 0 {
                        stk[pvt] = c
                        pvt++
                } else {
                        pvt--
                        fmt.Printf("%d\n", stk[pvt])
                }
        }
}

C++: #include<stack>
#include<deque>
#include<iostream>
using namespace std;
int main(){
	int m,n;
	deque<int>deq;
 	while(1){
	    cin>>n;
	    if(cin.eof()) break;
	    if(n!=0) deq.push_back(n);
	    else {  
                     if(deq.empty()) { continue;}
                     else {     cout<<deq[(int)deq.size()-1]<<endl;
				deq.pop_back();}
            }
	}
        return 0;
}

C++: #include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
int main(){
    stack <int> st;
    int n;
    while(cin >> n){
        if(n)
            st.push(n);
        else{
            cout << st.top() << endl;
            st.pop();
        }
    }
}

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

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

C++: #include<iostream>
#include<stack>
#include<vector>
int main(){
	std::stack<int> st;
	std::vector<int> vec;
	int a=0;
	while(1){
		int n;
		std::cin>>n;
		if(std::cin.eof())break;
		if(n!=0)st.push(n);
		else vec.push_back(st.top()),a++,st.pop();
	}
	for(int i=0;i<a;i++)std::cout<<vec[i]<<std::endl;
	return 0;
}

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

#define int64 long long int

using namespace std;

int main()
{
	int n;
	stack<int> st;

	while(cin >> n){
		if(n==0){
			cout << st.top() << '\n';
			st.pop();
		} else {
			st.push(n);
		}
	}	
	
	return 0;
}

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

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

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

int main(){
  std::stack<int>s;
  for(int x;~scanf("%d",&x);)
    if(x)s.push(x);
    else printf("%d\n",s.top()),s.pop();
}

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

int main(){
	int x;
	stack<int> S;
	while(1){
		cin>>x;
		if(x==0){
			printf("%d\n",S.top());
			S.pop();
		}else{
			S.push(x);
		}
	}
	return 0;
}

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

using namespace std;

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

  return 0;
}

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

int main(){
    stack<int>st;
    int x;
    while(cin >> x){
        if(x==0){
            cout << st.top() <<endl;
            st.pop();
        }else{
            st.push (x);
        }
    }    
    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[250][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[220] = {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 << 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 <iostream>
#include <stack>

using namespace std;

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

	while(cin >> n){
		if(n != 0){
			st.push(n);
		}else{
			cout << st.top() << endl;
			st.pop();
		}
		//if(st.empty() == true) break;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<stack>
using namespace std;
int main(){
    int tra,ans[20];
    stack<int> s;
    for(int i=0;i<20;i++){
        cin>>tra;
        if(tra==0){
            cout<<s.top()<<endl;
            s.pop();
        }else{
            s.push(tra);
        }
    }
}

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

using namespace std;
int num;
stack<int> s;

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

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

#define MAX 256

int main(void){
	
	int i=0,j=0,x;
	int a[MAX];
	int ans[MAX];
	while(cin>>x){
		if(x==0){
			ans[j]=a[i-1];
			j++;
			i--;
		}else{
			ans[i]=x;
			i++;
		}
		
		
	}
	
	for(int i=0;i<j;i++){
		cout<<ans[i]<<endl;
	}
	
}

C++: #include<iostream>

using namespace std;

int main() {
	int train[200000] = { 0 }, junban[200000] = { 0 }, a = 0, n, i;	
	while (cin >> n) {
		if (n == 0) {
			for (i = 0; train[i] != 0; i++) {}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; train[i] != 0; i++) {}
			train[i] = n;
		}
	}
	for (i = 0; junban[i] > 0; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  short stack[10]={0};
  short *pstack=stack;
  int num;
  while(cin>>num){
    if(num){
      *pstack=num;
      pstack++;
    }else{
      pstack--;
      cout<<*pstack<<endl;
    }
    if(pstack==stack) break;
  }
}

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

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

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


int main()
{
	int car[10] = {}, b[100];
	int i = 0, cou = 0;
	while (cin >> b[i]) {
		if (b[i] != 0) {
			car[cou] = b[i];
			cou++;
		}
		if (b[i] == 0) {
			cout << car[cou - 1] << endl;
			cou--;
		}
		i++;
	}
    return 0;
}

C++: #include <stdio.h>

int main(void){
	int stack[10];
	int sp = -1;
	int n = 0;
	for(int i=0;i<10;++i){
		stack[i] = 0;
	}
	while(scanf("%d", &n) != EOF){
		if(n == 0){
			printf("%d\n", stack[sp]);
			sp--;
		}else{
			stack[++sp] = n;
		}
	}
	return 0;
}

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

int main()
{
	stack<int> R;
	int n;
	int car[10];
	int i = 0;
	
	while (cin >> n){
		if (n == 0){
			car[i] = R.top();
			R.pop();
			i++;
		}
		else {
			R.push(n);
		}
	}
	
	for (int j = 0; j < i; j++){
		cout << car[j] << endl;
	}
	
	return (0);
}

C++: import java.util.ArrayDeque;
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	ArrayDeque<Integer> stack = new ArrayDeque<Integer>();
	int n;
	while (scan.hasNext()) {
	    n = Integer.parseInt(scan.nextLine());
	    if (n == 0) {
		System.out.println(stack.pop());
	    } else {
		stack.push(n);
	    }
	}
    }
}