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

vector<int> car,ans;

int main()
{
	while(true) {
		int n;
		scanf("%d",&n);
		if(n != 0) { car.push_back(n); }
		else {
			ans.push_back(car.back());
			car.pop_back();
		}
		if(car.empty()) { break; }
	}
	int Size = ans.size();
	for(int i=0;i<Size;++i) printf("%d\n",ans[i]);
	return 0;
}

C++:  /*
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.

We can simulate the movement (comings and goings) of the cars as follow:

An entry of a car is represented by its number.
An exit of a car is represented by 0
For example, a sequence

1 6 0 8 10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.

Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
 */
 
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	vector<int> cars(100000), ans;
	int temp, i=0, m;
	while (scanf("%d\n", &temp)) {
		if (temp != 0) {
			cars[i] = temp;
			i++;
		} else {
			int p = i-1;
			if (p < 0) {
				ans.push_back(cars[p]);
				i--;
			}
		}
	}
	for (int j=0; j<ans.size(); j++)
		cout << ans[j] << endl;
	return 0;
}

C++: #include <stdio.h>

#define N 20
int main(void){
    int stk[N], sp=0;
    int n;
   
    while (scanf("%d", &n)){
        if (n==0 && sp!=0){
            printf("%d\n", stk[--sp]);
        } else {
            stk[sp++] = n;
        }
    }
    return 0;
}

C++: #include <cstdio>

int main() {
  int ary[20],s=0,x;
  while(scanf("%d", &x)==1) {
    if(x) ary[s++] = x;
    else printf("%d\n", ary[--s]);
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b;
   stack<int> s;
  while(scanf("%d",&a)!=EOF){

    if(a!=0){
      s.push(a);
    }
    else{
      cout<<s.top()<<"\n";
      s.pop();
    }
  }
}

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

int main(){
int answer[10];
int a,b;
b=0;
stack<int> train;
while(cin>>a){
if(a==0){
answer[b]=train.top();
b++;
train.pop();}
if(a!=0){
train.push(a);}}
for(int i=0;i<b;i++){
cout<<answer[b]<<endl;}}

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

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

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

#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi  i <= _##i poi  i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi  i < _##i poi  i++)
#define downto(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi  i >= _##i poi  i--)
#define downtil(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi  i > _##i poi  i--)

#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define poi ;
#define poipoi << "\n"

#define fuwafuwa(n, c) dokidoki((n) + (c) - 1, c)
#define dokidoki(n, c) ((n) / (c) * (c))

template<class T> bool read(T& t){
    return cin >> t poi
}
template<class T, class...U> bool read(T& t, U&... u){
    unless(cin >> t) return false poi
    return read(u...) poi
}

template<class T> T toppo(stack<T>& stick){
    T choco = stick.top() poi
    stick.pop() poi
    return choco poi
}

int main(){
    int n poi
    stack<int> pyon poi

    while(read(n)){
        if(n) pyon.push(n) poi
        else cout << toppo(pyon) poipoi poi
    }

    return 0 poi
}

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

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

C++: #include <stdio.h>
int	main()	{
	int n,cnt =0,copy,i =0;
	int data[256];
	while(1){
		scanf("%d",&n);
		if(n != 0){
			data[i] = n;
			i++;
		}else if(n == 0){
			i--;
			printf("%d\n",data[i]);
		}
		if(i==0){
			break;
		}
	}
	return	0;
}

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

int main(){
	int  ans, in[10], out[10], i = 0, j = 1;

	while(cin >> in[i]){
		if(in[i] == 0){
			cout << in[i-j] << endl;
			i --;
		}
		else {
			i ++;
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  short stack[10]={0};
  short *pstack=stack;
  while(1){
    int num;
    cin>>num;
    if(num){
      *pstack=num;
      pstack++;
    }else{
      pstack--;
      cout<<*pstack<<endl;
    }
    if(pstack==stack) break;
  }
}

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

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

int main() {

	std::stack<int> st;//line
	int inp;//input

	while (std::cin >> inp)
	{
		if (inp == 0) {//output data and pop data
			std::cout << st.top() << std::endl;
			st.pop();
		}
		else {//push data
			st.push(inp);
		}
	}

	return 0;
}

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

int main()
{
    stack<int> entry,exits,out;
    int n;
    while(cin>>n)
    {
        if(n)
        {
            entry.push(n);
        }
        else
        {
            exits.push(entry.top());
            entry.pop();
        }
    }
    while(!exits.empty())
    {
        out.push(exits.top());
        exits.pop();
    }
    while(!out.empty())
    {
        cout<<out.top()<<endl;
        out.pop();
    }
    return 0;
}

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

int main(){
    int in;
    std::stack<int> st;

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

    return 0;
}

C++: #include<cstdio>
#include<stack>
#include<queue>
using namespace std;
int main(){
    stack<int>S;
    queue<int>Q;
    int train;
    while(scanf("%d",&train)!=EOF){

        if(train)S.push(train);
        else{
            Q.push(S.top());
            S.pop();
        }
    }
    while(!Q.empty()){
        printf("%d\n",Q.front());
        Q.pop();
    }

    return 0;
}

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

int main(){
    u_int a, end = 0;
    std :: vector<int> v = {};
    while(std :: cin >> a){
        if(a == 0){
            std :: cout << v.at(end-1) << std :: endl;
            v.pop_back();
            end--;
        } else{
            v.push_back(a);
            end++;
        }
    }
}

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