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

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

int main(){
   int syako[999];
   int i=1;
   
   cin>>syako[0];
   while(i>0){
      cin>>syako[i];
      i++;
      if(syako[i-1] == 0){
         printf("%d\n",syako[i]);
         i-=2;
      }
   }
   return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int in[10] = {0},out[10];
	int n;
	int i = 0;
	int j = 0;
	while(scanf("%d",&n) != EOF){
		if(n != 0){
			in[i] = n;
			i++;
		}
		else {
			i--;
			out[j] = in[i];
			j++;
			in[i] = 0;
		}
	}
	
	for(int i = 0;i < j;i++){
		cout << out[i] << endl;
	}
}

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

int main() {
  stack<int> sta;
  
  while(1){
  
    int temp;
    cin >> temp;
    
    if (temp==0){
      if (sta.empty()==false){
	cout << sta.top() <<endl;
	sta.pop();
      }
    }else{
      sta.push(temp);
    }
  }
    
  return 0;
  
}

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

int main(){
  stack<int> st;
  int a;
  while(cin>>a){
    if(a)st.push(a);
    else {printf("%d\n",st.top());
      st.pop();
      if(st.empty())break;
}

   }
  return 0;
}

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

int main()
{
    std::stack<int> cars;

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

    return 0;
}

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

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

int main(){

  std::stack<int> st;

  int N = 0;
  int a;

  while(N <= 100 && std::cin >> a){
    if(a != 0){
      st.push(a);
    }
    else{
      std::cout << st.top() << std::endl;
      st.pop();
	}
    ++N;
  }
}