Go: package main

import "fmt"

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

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}


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


}

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){
cout<<train.top()<<endl;
train.pop();}
if(a!=0){
	train.push(a);}}}

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

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

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

	
}

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

int main(){
    int n;
    std::stack<int> stack;
    while(1){
        std::cin >> n;
        if(n == 0){
            std::cout << stack.top() << std::endl;
            stack.pop();
        }
        else
        {
            stack.push(n);
        }
        if(std::cin.eof())
            break;
    }
}

C++: #include <iostream>
#include <vector>
#include <math.h>
#include <string>
#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++: #include <iostream>
#include <vector>
#include <stack>
using namespace std;

int main(){
  int e;
  stack<int> S;
  while(cin >> e){
    if(e > 0){
      S.push(e);
      continue;
    }
    cout << S.top() << endl;
    S.pop(); 
  }

  return 0;
}

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


  }


}