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++: #include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;

int main()
{
	int d;
	stack<int> q;
	while(~scanf("%d",&d)){
		if(d==0){
			printf("%d\n",q.top());
			q.pop();
		}
		else{
			q.push(d);
		}
	}		
}

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

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

using namespace std;

const int N = 1000000;

int stack[N], top;

int main() {
	int n;
	top = 0;
	while (scanf("%d", &n) != EOF) {
		if (n) stack[top++] = n;
		else printf ("%d\n", stack[--top]);
	}
	return 0;
}

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

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

C++: #include<stdio.h>
int main(){
  int sp=0,data[99],n,i;
  for(i=0;i<100;i++){
    scanf("%d",&n);
    if(n==0){
      sp--;
      printf("%d\n",data[sp]);
    }else{
      data[sp]=n;
      sp++;
    }
  }
}

C++: #include<cstdio>
#include<queue>
using namespace std;

int main(){
  int x;
  queue<int> q;
  while(scanf("%d", &x) != EOF){
    if(x == 0){
      printf("%d\n", q.top());
      q.pop();
    }
    else{
      q.push(x);
    }
  }
  return 0;
}

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

int main(){
  stack<int> a;
  int n;

  while(cin >> n){
    if(n != 0){
      a.push(n);
    }
    else if(a.size() == 0){
      int div = 9 / 10;
      cout << 10 / div << endl;
    }
    else{
      cout << a.top() << endl;
      a.pop();
    }
  }
}

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

using namespace std;

int main(){
 	
  int t=0,p,m,n[10];
 while(cin>>m){

   if(m!=0){n[t]=m;t++;}
   if(m==0){cout<<n[t-1]<<endl;n[t]=11;t--;}
}

return 0;
}

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

C++: #include<iostream>

#define MAX 256

int main(void){
	
	int i=0,j=0;
	int a[MAX];
	int ans[MAX];
	while(cin>>x){
		if(x==0){
			ans[j]=a[i-1];
			j++;
			i--;
		}else{
			ans[i]=x;
			i++;
		}
		
		
	}
	
	for(int i=0;i<j;i++){
		cout<<ans[i]<<endl
	}
	
}

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

int main(){

  int x, t[10], cnt=0;

  while(cin>>x){
    if(x==0){
      cnt--;
      cout<<t[cnt]<<endl;
    }else{
      t[cnt]=x;
      cnt++;
    }
  }
  
  return 0;
}

C++: #include<stdio.h> 
#include<stack> 
int main(){
	std::stack<int> s;     
	int n;     
	scanf("%d",&n);     
	s.push(n);
	while(scanf("%d",&n)!=EOF){
		if(n!=0)s.push(n);         
		else{             
			printf("%d\n",s.top());             
			s.pop();         
		}     
	} 
}

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

int main()
{
	int n;
	int cnt = 0;
	stack<int> car;
	vector<int> out;

	while (cin >> n, cin.eof() != true){
		if (n == 0){
			out.push_back(car.top());
			car.pop();
		}
		else {
			car.push(n);
		}
	}

	for (int i = 0; i < out.size(); i++){
		cout << out[i] << endl;
	}

	return (0);
}

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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

stack<int> st;
int x;

signed main() {
    while(cin>>x){
        if(x)st.push(x);
        else {
            std::cout << st.top() << '\n';
            st.pop();
        }
    }



    return 0;
}

C++: const int IN = 20, OUT = 100;
int data1[IN], data2[OUT];
int spA = 0, spB = 0;
int top(){
  return data1[spA - 1];
}
void pop(){
  spA--;
}

#include<stdio.h>
int main(){
  int i, n, c;
  while((c = getchar()) != EOF){
    scanf("%d", &n);
    if(n != 0){
      data1[spA] = n;
      spA++;
    }else{
      data2[spB] = top() ;
      spB++;
      pop();
    }
  }
  for(i = 0; i < spB; i++){
    printf("%d\n",data2[i]);
  }
  return 0;
}

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

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

C++: #include <iostream>
#include <stack>
using namespace std;
int main()
{
	stack<int> s;
	int k;
	while (cin >> k){
		if (0 == k){
			k = s.top();
			s.pop();
			cout << k << "\n";
		}
		else s.push(k);
	}
	return 0;
}

C++: #include<iostream>
#include<stack>
#include<cstdio>
using namespace std;
int main(){
  stack<int> train;
  int a;
   while(scanf("%d",&a)!=EOF){
    if(a==0){
    cout<<train.top()<<endl;
    train.pop();
    }
    else {
      train.push(a);
    }
  }
}

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

using namespace std;

int main(){
	stack<int> in;

    for(int n; cin >> n;)
        if(!n) cout << in.top() << endl, in.pop();
        else in.push(n);

	return 0;
}

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

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 w, n, now = 0, cou = 0;
	int list[MAX] = { 0 };
	int li[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 <iostream>
#include <cstdio>
#include <stack>
#include <vector>
using namespace std;

int main()
{
	int n;
	int cnt = 0;
	stack<int> car;
	vector<int> out;

	while (cin >> n){
		if (n == 0){
			out.push_back(cnt);
			out[cnt] = car.top(); // top pop
			car.pop();
			cnt++;
		}
		else {
			car.push(n);
		}
	}

	for (int i = 0; i < cnt; i++){
		cout << out[i] << endl;
	}

	return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,a[1000]={},cnt=0;
	while(cin >> n){
		if(n==0){
			cout << a[cnt-1] << endl;
			cnt--;
		}else{
			a[cnt]=n;
			cnt++;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
int x;
stack<int>s;
int main() {
	while (cin >> x) {
		if (x)s.push(x);
		else {
			cout << s.top() << endl;
			s.pop();
		}
	}
	
	getchar();getchar();
	return 0;
}