Go: package main

import "fmt"

func main() {
	var i int
	stack := make([]int, 0)
	for {
		v, _ := fmt.Scan(&i)
		// fmt.Println(stack)
		// println(v)
		if v == 0 {
			break
		}
		if i == 0 {
			fmt.Println(stack[len(stack)-1])
			stack = stack[:len(stack)-1]
			continue
		}
		stack = append(stack, i)
	}
}

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>

using namespace std;

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

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

int main(){
	int a[30];
	int i = 0;

	for (int i = 0; i < 30; i++){
		a[i] = 0;
	}

	while (1){
		i++;
		cin >> a[i];
		if (a[i] == 0){
			int j = i+1;
			while (1){
				j--;
				if (a[j] != 0){
					cout << a[j] << endl;
					a[j] = 0;
					break;
				}
			}
		}
	}


	return 0;
}

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

int main( void )
{
	stack <int> S;
	int first;
	cin >> first;
	S.push( first );

	string kotae = "";
	while ( S.empty() == false )
	{
		int n;
		cin >> n;
		if ( n == 0 )
		{
			kotae += ('0' + S.top());
			kotae += '\n';
			S.pop();
		}
		else
		{
			S.push( n );
		}
	}

	cout << kotae;

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