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 <iostream>
#include <vector>
using namespace std;

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

C++: #include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <iterator>

static int createListOfInputData(std::vector<int>& vec);
static int switchingRailroadCars(std::vector<int>& vec, std::vector<int>& data);
static void showData(std::vector<int>& vec);

int main()
{
    std::vector<int> v;
    std::vector<int> r;

    if (createListOfInputData(v)) {
        std::cout << "Failure";
        exit (8);
    }

    if (switchingRailroadCars(v, r)) {
        std::cout << "Failure";
        exit (8);
    }

    showData(r);

    return 0;
}

static int createListOfInputData(std::vector<int>& vec)
{
    int t = 0;

    if ( 0x00 == &vec ) {
        return 1;
    }

    while (std::cin >> t) {
        if ( 100 < t ) {
            return 1;
        }
        vec.push_back(t);
    }

    return 0;
}

static int switchingRailroadCars(std::vector<int>& vec, std::vector<int>& data)
{
    std::vector<int>::iterator it;

    if ( 0x00 == &vec ) {
        return 1;
    }

    it = vec.begin();

    while (vec.end() != it) {
        if ( 0 == *it ) {
            data.push_back(*(it - 1));
            vec.erase(it);
            it = vec.erase(it - 1);
        } else {
            it++;
        }
    }

    return 0;
}

static void showData(std::vector<int>& vec)
{
    if ( 0x00 == &vec ) {
        return;
    }

    for ( unsigned int i = 0; i < vec.size(); i++ ) {
        std::cout << vec.at(i) << std::endl;
    }
}

C++: //外積を使う

#include<iostream>
#include<string>
#include<stdio.h>
#include<vector>

using namespace std;


int main(){
	
	vector<int> stack;

	int i = 0;
	int ret;

	while (scanf("%d", &ret) != EOF){
		if (ret != 0){
			stack.push_back(ret);
		}
		else{
			cout << stack[stack.size()-1]<< endl;
			stack.pop_back();
		}
	}


	return 0;
}

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

int main()
{
	stack<int> s;
	deque<int> ans;
	int n;

	while (cin >> n)
	{
		if (cin.eof()) return 0;
		if (n == 0)
		{
			ans.push_front(s.top());
			s.pop();
			if (s.empty()) break;
		}
		else
		{
			s.push(n);
		}
	}

	while (1)
	{
		if (!ans.empty())
		{
			cout << ans.back() << endl;
			ans.pop_back();
		}
		else break;
	}
	return 0;
}

C++: #include <iostream>
  
struct Stack{
  int data[100000];
  int idx;
  Stack():idx(0){}
  void push(int val){ data[idx++]=val;}
  int pop(){ return data[--idx];}
};

int main(){
  Stack s;
  int val;
  while(std::cin>>val){
    if(val==0)
      std::cout<<s.pop()<<std::endl;
    else
      s.push(val);
  }
  return 0;
}

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