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 <stack>
  
int main(){
    std::stack<u_int> train;
    u_int num;
    while(std::cin >> num){
        if(num == 0){
            std::cout << train.top() << std::endl;
            train.pop();
        }
        else {
            train.push(num);
        }
    }
    return 0;
}

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int input;
    stack<int> sta;

    while(cin >> input)
    {
        if(input == 0)
        {
            cout << sta.top() << endl;
            sta.pop();
        }    
        else
        {
            sta.push(input);
        }
    }

    return 0;
}

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

int main()
{
    std::stack<int> s;
    while (true) {
        int n;
        std::cin >> n;
        if (std::cin.eof()) break;

        if (n == 0) {
            std::cout << s.top() << std::endl;
            s.pop();
        }
        else s.push(n);
    }
}

C++: #include<stdio.h>
int main(){
int a[100];
int j;
for(int i=0;;i++){
scanf("%d",&a[i]);
if(a[i]==0){
j=i;
while(){
if(j1!=0){
printf("%d",a[j1]);
break;
}
j--;
}
a[j-1]=0;
}
}

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

using namespace std;

int n;
int a[10000];
int i = 0;

int main(void)
{
	stack<int> s;
	while(scanf("%d", &n) != EOF){
		if(n == 0){
			a[i] = s.top();
			s.pop();
			i++;
		}
		else{
			s.push(n);
		}
	}
	
	for(int j = 0; j < i; j++){
		printf("%d\n", a[j]);
	}
	
	return 0;
}

C++: #include<stdio.h>


struct STACK
{
	int num[ 10 ] ;
	int p ;
	
	int		Top( void )	;
	void	Push( int )	;
	void	Pop( void )	;
	void	Init( void ) ;
} stack ;


int main( void )
{
	stack.Init() ;

	int kale ;
	while( scanf( "%d" ,&kale ) != EOF )
	{
		if( kale == 0 )
		{
			printf( "%d\n" ,stack.Top() ) ;

			stack.Pop() ;
		}

		else
		{
			stack.Push( kale ) ;
		}
	}

	return 0 ;
}


void STACK::Init( void )
{
	p = 0 ;
}

void STACK::Push( int kale )
{
	num[ p++ ] = kale ;
}

void STACK::Pop( void )
{
	--p ;
}

int STACK::Top( void )
{
	return num[ p - 1 ] ;
}

C++: #include<iostream>
using namespace std;
int main(){
  
  int a[10],b[10],c=0,d=0,num;

  while(1){

    cin >>num;

    if(num != 0){
      a[c]=num;
      c++;
    }else{
      b[d]=a[c-1];
      c--;
      d++;
    }

    if( c == 0 )break;

  }

  for(int i=0 ; i < d ; i++){
    cout <<b[i]<<endl;
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main (int argc, char * const argv[]) {
    // insert code here...
    int n;
	vector<int> densha;
	
	while(cin>>n){
		if(n==0){
			cout << densha[densha.size()-1]<<endl;
			densha.pop_back();
		}else{
			densha.push_back(n);
		}
	}
	
	return 0;
}

C++: import java.io.*;

 public class Main{
	 public static void main(String args[]) throws IOException{
		 BufferedReader bf = new BufferedReader(
				 new InputStreamReader(System.in));
		 int i = 0, j = 0,x;
		 int order[] = new int[10];
		 int exit[] = new int[1000];
		 String str;
		 while((str = bf.readLine()) != null){
			 x = Integer.parseInt(str);
			 if(x != 0){
				 order[i] = x;
				 i++;
			 } else {
				 exit[j] = order[i-1];
				 j++;
				 i--;
			 }
		 }
		 for(int c = 0; c < j; c++){
			 System.out.println(exit[c]);
		 }
	 }
}

C++: #include<stdio.h>
int main(){
  int sp=0,data[9],n,i;
  for(i=0;i<100;i++){
    scanf("%d",&n);
    if(n==0 && sp>0){
      sp--;
      printf("%d\n",data[sp]);
    }else{
      data[sp]=n;
      sp++;
    }
    if(sp==0)break;
  }
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	stack<int> car;
	int n;

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

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

using namespace std;

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

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

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

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

int main() {
int k=0,b;
int a[1000000];
while(cin>>b){
	if(b!=0){
		a[k]=b;
		k=k+1;
	}
	if(b==0){
		cout<<a[k-1]<<endl;
		k=k-1;
	
}
}
	return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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