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>
#include <algorithm>

using namespace std;

int main() {
	vector<int> cars(100000), ans;
	int temp, i=0, m;
	while (cin >> 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 <iostream>
#include <stack>

int main(int argc,char* argv[]){
  std::stack<int> vec;
  
  while(!std::cin.eof()){
    int temp;
    std::cin >> temp;
    if(temp == 0){
      std::cout << vec.top() << std::endl;
      vec.pop();
      continue;
    }else{
      vec.push(temp);
      continue;
    }
  }

  return 0;
  
}

C++: #include <iostream>
#include <stack>
int main()
{
  int n;
  std::stack<int> trains;
  while (std::cin >> n) {
    if (n == 0) {
      std::cout << trains.top() << std::endl;
      trains.pop();
    } else {
      trains.push(n);
    }
  }
  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 <cstdio>
#include <stack>
using namespace std;

int main(void){
  stack<int> data;
  int a;

  while(scanf("%d",&a) != EOF){
    if(a) data.push(a);
    else {
      if(data.empty()) break;
      printf("%d\n",data.top());
      data.pop();
    }
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(void)
{
    vector<int> t;
    int a;
    while (true)
    {
        cin >> a;
        if (a != 0)
        {
            t.push_back(a);
        }
        else if (a == 0)
        {
            cout << t.back() << endl;
            t.pop_back();
        }
        if (t.empty())
        {
            break;
        }
    }
}

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

using namespace std;

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

C++: /*
車両の出入り。
入力された番号の車両が格納されていき、0が入力されたときは、
最後に格納した（1番手前にある）車両の番号を表示し、出発させる。
*/

#include <iostream>
using namespace std;

int main(void) {
    int garage[100] = {};
    int size;
    int i = 0;
    int number;
    
    while(cin >> number) {
        if(number == 0) {
            i--;
            if(i < 0) {
                break;
            }
            cout << garage[i] << endl;
        } else {
            garage[i] = number;
            i++;
        }
    }
}

C++: #define scanf_s scanf
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 100
int main(void)
{
	int w, n, now = 0;
	int list[MAX] = { 0 };
	do{	
		scanf_s("%d", &n);
		if (n != 0) { list[now] = n; ++now; }
		else { --now; printf("%d\n", list[now]); }
	} while (now != 0);
}

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

string str1[11],str2[11],mo;

int  s=1,t1,t2;

int main(){


    while(1){

    cin >> mo;


    if(mo!="0"){
        str1[t1]=mo;
        t1++;

    }else {
        str2[t2++]=str1[--t1];

    }

    if(t1==0)break;

    }

    for(int i=0;i<11;i++){

            if(str2[i]=="0")break;
        cout << str2[i] << endl;
    }


return 0;
}

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

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

C++: #include <iostream>
#include <algorithm>
#include<string>
using namespace std;
int top,s[105];
void push(int x){
    s[++top]=x;
}
void pop(){
    top--;
    cout<<s[top+1]<<endl;
}
int main(){
    int num;
    while(1){
        cin>>num;
        if(num==0)
            pop();
        else push(num);
    }
    return 0;
}

C++: #include <stdio.h>

int main()
{
int p[11]={};
int x,i;
i=0;x=0;
while(scanf("%d",&x)!=EOF)
{
if(x>0){p[i]=x;i++;}
else{i--;printf("%d\n",p[i]);}

}
return 0;
}

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

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

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

int main()
{
	int train[100000]={};
	long int i=0;
	while(1){
		cin>>train[i];
		if(train[i]==0){
			i--;
			cout<<train[i]<<endl;
		}else{
			i++;
		}
		if(i==0) break;
	}
}

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

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

C++: #include<iostream>
#include<stack>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

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

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

int main(){

	std::stack<int> train;

	int buf;

	while(std::cin >> buf){

		if(buf == 0){

			std::cout << train.top() << endl;
			train.pop();

		}else{

			train.push(buf);

		}
	
	}

	return 0;
}