Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Railway struct {
	trains trains
}

type trains []int

func main() {
	var stdin string
	var s = bufio.NewScanner(os.Stdin)

	railway := Railway{}
	for s.Scan() {
		stdin = s.Text()

		n, err := strconv.Atoi(stdin)
		if err != nil {
			continue
		}
		railway.lifo(n)
	}
}

func (r *Railway) lifo(n int) {
	if n == 0 {
		if len(r.trains) == 0 {
			return
		}
		fmt.Println(r.trains[len(r.trains)-1])
		r.trains = r.trains[:len(r.trains)-1]
	} else {
		r.trains = append(r.trains, n)
	}
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>

using namespace std;

typedef complex<double> P;

int main(){

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

	return 0;
}

C++: #include <stdio.h>

int train[10];
int sp = 0;

int empty() {
  return sp <= 0;
}

int size() {
  return sp;
}

int top() {
  return train[sp-1];
}

void pop() {
  sp--;
}

void push(int v) {
  train[sp] = v;
  sp++;
}

int main(){
  int out[10];
  int num, i = 0;
  while(1){
    scanf("%d", &num);
    if(num == 0){
      out[i] = top();
      i++;
      pop();
    }else if(1 <= num && num <= 10){
      push(num);
    }
    if(size() == 0) break;
  }
  for(i = 0; i < 10; i++){
    printf("%d\n", out[i]);
  }
  return 0;
}

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

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

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

int main()
{
	int n;
	vector<int> cars;
	vector<int> order;
	while (cin >> n) {
		if (n==0)  {
			order.push_back(cars.back());
			cars.pop_back();
		}
		else
			cars.push_back(n);
		if (cars.size() == 0)
			break;
	}

	for (int i=0;i<order.size();i++)
		cout << order[i] << endl;

	return 0;
}

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

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

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

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	stack<int> S;
	int n;
	cin >> n;
	S.push(n);
	vi ans;
	while(!S.empty()) {
		cin >> n;
		if(n) {
			S.push(n);
		} else {
			ans.push_back(S.top());
			S.pop();
		}
	}
	
	REP(i, ans.size()) {
		cout << ans[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.src", "r", stdin);
	string str = "";
	stack <int> R;

	while ( getline (cin, str )){
		int n;
		stringstream ss(str);
		ss >> n;
		if (n != 0){
			R.push(n);
		}else if (n == 0 && !R.empty()){
			cout << R.top() << endl;
			R.pop();
		} // end if
	} // end for

	return 0;
}

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++: //////////////////////////////////0013
#include <iostream>
using namespace std;

int main(){
	
	int num,in;
	while(cin>>in){
		if(in == 0){
			cout<<num<<endl;
		}else{
			in=num;
		}
	}
	return 0;
	
}

C++: #include "stdio.h"
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]){
    int input; 
    int input_order[100];
    stack<int> train_stack;
    vector<int> order;

    while (~scanf("%d", &input)){
        if (input==0){
            cout<<train_stack.top()<<endl;
            train_stack.pop();
        }
        else{
            train_stack.push(input);
        }
    }
    return 0;
}

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

C++: #include <iostream>
#include <stack>
using namespace std;
int main()
{
	stack<int>s;
	int n;
	while (cin >> n)
	{
		if (n!= 0)
		{
			s.push(n);
		}
		else
		{
			cout << s.top() << endl;
			s.pop();
		}
	}
};

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

int main(void)
{
	stack<int> s;
	int zug;

	while (cin >> zug) {
		if (zug > 0) s.push(zug);
		else {
			cout << s.top() << endl;
			s.pop();
		}
	}
	
	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<20;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*****/
#include <iostream>
#include <fstream>
#include <list>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****変数置き場*****/
	list<int> V;
	int order;
	/*****処理部*****/
	while(1){
		cin >> order;
		if(order == 0){
			cout << V.back() << endl;
			V.pop_back();
		}else{
			V.push_back(order);
		}
	}
	return 0;
}

C++: #include<stdio.h>
const int SIZE=100;
int data[SIZE]={0};
int sp=0;
int size(){
  return sp;
}
int empty(){
  return sp<=0;
}
int isfull(){
  return sp>=SIZE;
}
int top(){
  return data[sp-1];
}
void pop(){
  sp--;
}
void push(int v){
  data[sp]=v;
  sp++;
}
int main(){
  int k,n;
  for(k=0;k<100;k++){
    scanf("%d",&n);
    if(empty()&&n==0)break;
    if(!empty()&&n==0){
      printf("%d\n",top());
      pop();
    }else if(!isfull()){
      push(n);
    }
  }
  return 0;
}