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>
#include<stdio.h>
using namespace std;
int main(){
  int train[10],n,i;
  n = 0;
  int order[100],intrain[10];
  for( i = 1;i <= 10;i++){
    train[i] = i;
  }
  for(i=0;i<100;i++)
    order[i] = 11;
  i = 0;
  while(scanf("%d",&order[i]) != EOF){i++;}
  for(i = 0;order[i] != 11;i++){
    if(order[i] != 0){
      intrain[n] = order[i]; n++;}else if(order[i] == 0){
      n--;      cout << intrain[n] << endl;}
  }
}

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

int main()
{
    int train[10]={0},n,count=0,outTrain[10],trainCount=0;
    while(scanf("%d",&n)!=EOF){
        if(n){
            for(int i=count ; i!=0 ; i--){
                train[i]=train[i-1];
            }
            train[0]=n;
            count++;
        }
        else{
            outTrain[trainCount]=train[0];
            for(int i=0 ; i<count ; i++){
                train[i]=train[i+1];
            }
            train[count]=0;
            count--;
            trainCount++;
        }
    }
    for(int i=0 ; i<trainCount ; i++){
        cout << outTrain[i] << '\n';
    }
    return 0;
}