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 <bits/stdc++.h>
#define rep(i,l,n) for(i=l;i<n;i++)
using namespace std;

int main(){
	int data[15]={},i=0,n;

	while(1){
		cin>>n;
		if(n!=0){
			data[i]=n;
			i++;
		}else if(n==0){
			cout<<data[i-1]<<endl;
			i--;
		}
	}
}

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

int main()
{
	stack<int> car;
	vector<int> outlist;

	while( !car.empty() || outlist.empty() )
	{
		int carnum;
		cin >> carnum;
		if(carnum)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}
	
	cout << outlist[i] << '\n';
	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<stack>
#include<algorithm>
using namespace std;
int main(void){
    int j=0;
	int k;
	int b[1000]={0};
	stack<int> a;
	a.push(-1);
	for(int i=0;;i++){
        if(i>=1&&a.top()==-1)break;
        cin>>k;

        if(k==0){
            b[j]=a.top();
            j++;
            a.pop();
        }
        else a.push(k);
	}
	for(int i=0;i<j;i++){
        cout<<b[i]<<endl;
	}


	return 0;
}

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

int main()
{
    int n;
    vector<int> car;
    while (cin >> n) {
        if (n) {
            car.push_back(n);
        }
        else {
            cout << car.back() << endl;
            car.pop_back();
        }
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>


using namespace std;

int main()
{
	int n;
	stack<int> s;
	while (scanf("%d", &n) != EOF)
	{
		if (n == 0)
		{
			printf("%d\n", s.top());
			s.pop();
		}
		else
		{
			s.push(n);
		}
	}

	return 0;
}

C++: #include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp= 0;

void pop(){
 sp--;
}

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

int main(){
 int v;
 while(scanf("%d", &v) != EOF){
  if(v != 0){
   push(v);
  }
  if(v == 0){
   printf("%d\n", top());
   pop();
  }
 }
 return 0;
}

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

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

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

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

using namespace std;

int main()
{
	stack<int> hako;
	int temp[100];
	int t, i = 0;
	
	cin >> t;
	
	hako.push(t);
	while(hako.size() != 0){
		cin >> t;
		if(t == 0){
			temp[i] = hako.top();
			hako.pop();
			i++;
		}
		else{
			hako.push(t);
		}
	}
	
	for(int j = 0; j < i; j++){
		cout << temp[j] << endl;
	}
	
}

C++: #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <queue>
#include <vector>

using namespace std;

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

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

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

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

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

using namespace std;

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

C++: #include<iostream>

using namespace std;

int main() {
	int train[11] = { 0 }, junban[11] = { 0 }, a = 0, n, i;	
	while (cin >> n) {
		if (n == 0) {
			for (i = 0; train[i] != 0; i++) {}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; train[i] != 0; i++) {}
			train[i] = n;
		}
	}
	for (i = 0; junban[i] > 0; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}

C++: #include<iostream>int main(){int a,c=0,s[12];while(std::cin>>a){if(a!=0)s[c++]=a;else std::cout<<s[--c]<<"\n";}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 <vector>
#include <algorithm>

using namespace std;

int main() {
	vector<int> cars, ans;
	int temp, i=0, m;
	while (cin >> temp) {
		if (temp != 0) {
			cars[i] = temp;
			i++;
		} else {
			ans.push_back(cars.at(i-1));
			i--;
		}
	}
	for (int j=0; j<ans.size(); j++)
		cout << ans[j] << endl;
	return 0;
}

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

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

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

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

C++: #include<iostream>
#include<vector>
int main(){
	std::vector<int> car,ans;
	int a;
	//int h=0;
	bool f=false;
	//std::vector<int>::iterator it=car.begin();
	while(std::cin>>a){
		if(a!=0&&!f){
			car.push_back(a);
			f=true;
		}else if(a!=0){
			//h++;
			//++it;
			car.push_back(a);
		}else{
			//ans.push_back(car[h]);
			//ans.push_back(n);
			ans.push_back(car.back());
			//it--;
			car.pop_back();
			//h--;
		}
	}
	for(int i=0;i<ans.size();i++){
		std::cout<<ans[i]<<std::endl;
	}

	return 0;
}

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

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

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

#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)

int main(){
	int n;
	stack<int> st;

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

	return 0;
}