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() {

	std::stack<int> st;//line
	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>
#include<iomanip>
#include<stack>
using namespace std;

int main()
{
    stack<int> entry,exits,out;
    int n;
    while(cin>>n)
    {
        if(n)
        {
            entry.push(n);
        }
        else
        {
            exits.push(entry.top());
            entry.pop();
        }
    }
    while(!exits.empty())
    {
        out.push(exits.top());
        exits.pop();
    }
    while(!out.empty())
    {
        cout<<out.top()<<endl;
        out.pop();
    }
    return 0;
}

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

int main(){
    int in;
    std::stack<int> st;

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

    return 0;
}

C++: #include<cstdio>
#include<stack>
#include<queue>
using namespace std;
int main(){
    stack<int>S;
    queue<int>Q;
    int train;
    while(scanf("%d",&train)!=EOF){

        if(train)S.push(train);
        else{
            Q.push(S.top());
            S.pop();
        }
    }
    while(!Q.empty()){
        printf("%d\n",Q.front());
        Q.pop();
    }

    return 0;
}

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

int main(){
    u_int a, end = 0;
    std :: vector<int> v = {};
    while(std :: cin >> a){
        if(a == 0){
            std :: cout << v.at(end-1) << std :: endl;
            v.pop_back();
            end--;
        } else{
            v.push_back(a);
            end++;
        }
    }
}

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

int main(){

	std::vector<int> vehicle_order;
	int input_data;

	while(std::cin >> input_data){
		if(input_data == 0){
			std::cout << vehicle_order.back() << std::endl;
			vehicle_order.pop_back();
		}else{
			vehicle_order.push_back(input_data);
	}
	}

	return 0;
}

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

int main(void){
    vector<int> v;
    int i;
    while(cin >> i){
        if(i == 0){
            cout << v[v.size() - 1] << endl;
            v.pop_back();
        } else {
            v.push_back(i);
        }
    }
}

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

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

C++: #include <bits/stdc++.h>

using namespace std;

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

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

int main(){
	std::stack<int> trains;
	int in;

	while(std::cin >> in){
		if(in == 0){
			std::cout << trains.top() << std::endl;
			trains.pop();
		}
		else
			trains.push(in);
	}
	return 0;
}

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

int main(int argc,char* argv[]){
  std::stack<int> vec;
  int temp;
  
  while(std::cin >> temp){
    if(temp == 0){
      int a = vec.top();
      std::cout << a << std::endl;
      vec.pop();
      continue;
    }else{
      vec.push(temp);
      continue;
    }
  }

  return 0;
  
}

C++: #include<iostream>

using namespace std;

int main() {
	int train[10] = { 0 }, junban[10] = { 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() {
  int n, array[100];
  int pointer = 0;
  while (cin >> n) {
    if (n == 0) {
      cout << array[--pointer] << endl;
    } else {
    array[pointer++] = n;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){

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

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

int main(){
	
	int n=1;
	int x;
	stack<int> y;
	
	for( int i=1 ; i<=n ; i++){
		cin >> x ;
		if(x!=0){
			n=n*2;
			y.push( x );
		}
		else{
			cout << y.top() << endl ;
			y.pop();
		}
	}
return 0;
}

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

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

	}
	return 0;
}

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

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int car[100],num,i=0;
	while(cin>>num){
		if(num==0){
			i--;
			cout<<car[i]<<endl;
		}else{
			car[i]=num;
			i++;
		}
	}
	return 0;
}

C++: 
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		Stack<Integer> stack = new Stack<Integer>();
		while (scn.hasNext()) {
			int n = scn.nextInt();
			if (n == 0) {
				System.out.println(stack.pop());
			} else {
				stack.push(n);
			}
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#define rep(x,to) for(x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;




int main(void){

stack<int> stk;
int ww;	

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

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

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

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

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

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

int main()
{
	int train[100000]={};
	long int i=0;
	while(1){
		cin>>train[i];
		if(train[i]==0){
			i--;
			cout<<train[i]<<endl;
		}else{
			i++;
		}
	}
}