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

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

int main(){
stack<int>a;
int b;
scanf("%d",&b);
a.push(b);
while(cin>>b){
	if(b)a.push(b);
	else {printf("%d\n",a.top());a.pop();}
}
}

C++: #include<stdio.h>
int main(){
	int a,b,c,d,train[100];
	b=0;
	c=0;
	
	int g;
	int cont = 0;
	
	for(a=0;a<1000;a++){
		if(scanf("%d",&g)==-1){
			break;
		}
		
		if(g != 0){
			train[cont] = g;
			cont++;
		}
		else{
			printf("%d\n",train[cont-1]);
			cont--;
		}
		/*
		if(cont == 0){
			break;
		}
		*/
		/*
		if(train[a]==0){
			c++;
		}else{
			b++;
		}
		if(b==c){
		break;
		} 
		*/
	}
	return 0;
}

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

int main(){
   int i=0,n,m,x;
   int syaryo[999];
   stack<int>st;
   cin>>n;
   st.push(n);
   
   while(1){
      if(st.empty())
         break;
      cin>>n;
      if(n==0){
         m = st.top();
         st.pop();
         syaryo[i] = m;
         i++;
      }
      else
         st.push(n);
   }
   for(x=0;x<i;x++) printf("%d\n",syaryo[x]);
     
   return 0;
}

C++: #include <stdio.h>

int main() {
	int a,i,k,m;
	int data[15] = {0};
	int output[15] = {0};
	while(scanf("%d", &a) != EOF) {
		if (a != 0) {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					data[k] = a;
					break;
				}
			}
		}
		else {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					for (m = 0; m < 15; m++) {
						if (output[m] == 0) {
							output[m] = data[k - 1];
							break;
						}
					}
					data[k - 1] = 0;
					break;
				}
			}
		}
	}
	for (i = 0; i < 15; i++) {
		if (output[i] != 0) {
			printf("%d\n", output[i]);
		}
	}
	return 0;
}

C++: #include<stdio.h>

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

C++: #include<iostream>
using namespace  std;
int rail[10];
int it = -1;
int main()
{
	int n;
	while (cin >> n)
	{
		if (n == 0)
		{
			cout << rail[it] << endl;
			it--;
		}
		else
		{
			it++;
			rail[it] = n;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

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

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

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

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

C++: #include<iostream>
using namespace std;
main(){
  int i=0,num,a[10];
  while(cin>>num){
    if(num)a[i++]=num;
    else cout<<a[--i]<<endl;
  } 
}

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

struct stack{
	int element;
	struct stack *next;
};
int top(struct stack *s){
	return s->element;
}
struct stack* pop(struct stack *s){
	struct stack *p, *q;
	q = s;
	p = s->next;
	free(q);
	s = p;
	return s;
}
struct stack* push(struct stack *s, int x){
	struct stack *p, *q;
	q = s;
	p = (struct stack*)malloc(sizeof(struct stack));
	p->element = x;
	p->next = q;
	s = p;
	return s;
}

int main(){
	struct stack *S=NULL;
	int num;
	while (cin>>num){	
		if (num==0){
			cout<<top(S)<<endl;
			S = pop(S);
		} else{
			S=push(S, num);
		}
	}
	return 0;
}

C++: 
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 0; i < 600 / n; i++) {
			ans += 600/n*i;
		}
		ans *= 600 / n;
		cout << ans << endl;
	}
}

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

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

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int x;
  stack<int> s;
  queue<int> q;
  while (cin >> x) {
    if (x == 0) {
      q.push(s.top());
      s.pop();
    } else {
      s.push(x);
    }
  }
  for (; q.size(); q.pop()) cout << q.front() << endl;
}

C++:     #include <iostream>
    using namespace std;
     
    int a[11], b[11], c, t;
     
    int main() {
      cin>>a[0];
      t=1;
      c=0;
     
      while(t>1) {
        cin>>a[t];
        if(a[t]>0) {
          t++;
        }else {
          b[c]=a[t-1];
          c++;
          t--;
        }
      }
     
      for(int i=0;i<c;i++) {
      	cout<<b[i]<<endl;
      }
     
      return 0;
    }

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

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

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

int main()
{
	std::stack<int> s;
	int x;
	while( std::cin >> x ){
	 	if( x ) s.push( x );
		else{
		 	std::cout << s.top() << std::endl;
			s.pop();
		}
	}

 	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  
  int a[10],c=0,num;

  while( scanf("%d",&num) != EOF ){

    if( num != 0 ){
      a[c]=num;
      c++;
    }else{
      cout <<a[c-1]<<endl;
      c--;
    }   

  }
  return 0;

}