Go: package main

import (
        "fmt"
)

func main() {
        var stk [101]int
        var c int
        pvt := 0
        for {
                _, err := fmt.Scanf("%d", &c)
                if err != nil {
                        break
                }
                if c > 0 {
                        stk[pvt] = c
                        pvt++
                } else {
                        pvt--
                        fmt.Printf("%d\n", stk[pvt])
                }
        }
}

C++: #define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	vector<int> a;
	int n;
	for (; cin >> n;)
	{
		if (n == 0)
		{
			cout << a.back() << endl;
			a.pop_back();
		}
		else
		{
			a.push_back(n);
		}
	}
}

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() {
  stack<int> cars;
  int command;  //??\???????????????

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

  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 {
			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>
#include<queue>
using namespace std;

int main(){
	stack<int> st;
	queue<int> q;
	int input;

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

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

using namespace std;

int main() {
  stack<int> s;

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

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

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

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

int a[1000];
int b,c;

int main()
{
	b=0;
	for(int z=0;z<1000;z++)
	{
		if (z==0)
		{
			a[0]=1;
		}
		else
		a[z]=0;
	}
	while(a[0]!=0)
	{
		scanf("%d",&a[b]);
		if(a[b]==0)
		{
			for(c=99;c>=0;c--)
			{
				if(a[c]!=0)
				{
					printf("%d\n",a[c]);
					a[c]=0;
					break;
				}
			}
		}
		b++;
	}
	return 0;
}

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

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

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


int main(){

  stack<int> st;
  int n, a;

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


  }


}

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

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

C++: #include <iostream>
#include<iomanip>
#include <vector>
#include <algorithm>
#include<math.h>
using namespace std;

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

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

  return (0);
}

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

using namespace std;

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

    cin>>input;
    train_stack.push(input);
    while (!train_stack.empty()){
        cin>>input;
        if (input==0){
            order.push_back(train_stack.top());
            train_stack.pop();
        }
        else{
            train_stack.push(input);
        }
    }

    for (const auto& tarin_num : order){
        cout<<tarin_num<<endl;
    }
    
    return 0;
}

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

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

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

using namespace std;

int main() {
	stack<int> st;
	int n;
	while (cin >> n) {
		if (n != 0)
			st.push(n);
		else {
			cout << st.top() << endl;
			st.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<stack>
using namespace std;

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

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

int main(void){
	std::stack<int> s;
	do{
		int in;
		std::cin >> in;
		if(!in){
			std::cout << s.top() << std::endl;
			s.pop();
		}else{
			s.push(in);
		}
	}while(!s.empty());
	return 0;
}

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

using namespace std;

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

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

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

using namespace std;

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