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

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

C++: //Vol0 0013
#include<stdio.h>
int main()
{
	int n,buf[128]={0},i=0;
	while(!(scanf("%d",&n)==EOF)){
		if(n==0){
			if(i!=0){
				i--;
			}
			printf("%d\n",buf[i]);
			buf[i]=0;
		}else{
			buf[i]=n;
			i++;
		}
	}
	return 0;
}

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

using namespace std;

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

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

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

C++: #include<iostream>

using namespace std;

int main() {
	int train[20] = { 0 }, junban[20] = { 0 }, a = 0, n, i;	
	while (cin >> n) {
		if (n == 0) {
			for (i = 0; train[i] != 0; i++) {i+1;}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; train[i] != 0; i++) {i+1;}
			train[i] = n;
		}
	}
	for (i = 0; junban[i] > 0; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}

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

using namespace std;

int n;
int a[10];
int i = 0;

int main()
{
	stack<int> s;
	while(scanf("%d", &n) != EOF){
		if(n == 0){
			a[i] = s.top();
			s.pop();
			i++;
		}
		else{
			s.push(n);
		}
	}
	
	for(int j = 0; j < i; j++){
		printf("%d\n", a[j]);
	}
	
	return 0;
}

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

using namespace std;

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

C++: #include <iostream>

using namespace std;

int main(){
    int track[10], c, num;
    while(1){
        cin >> num;
        if(!num){
            if(!c) cout << "No train" << endl;
            else cout << track[c--] <<endl;
        }
        else{
            if(c==10) cout << "Already Full" <<endl;
            else track[++c] = num;
        }
    }
    return 0;
}

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

int main()
{
	stack<int> s;
	deque<int> ans;
	int n;

	while (1)
	{
		cin >> n;
		if (n == 0)
		{
			ans.push_front(s.top());
			s.pop();
			if (s.empty()) break;
		}
		else
		{
			s.push(n);
		}
	}

	while (1)
	{
		if (!ans.empty())
		{
			cout << ans.back() << endl;
			ans.pop_back();
		}
		else break;
	}
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int car;
  stack<int> st;
  vector<int> result;

  while (cin >> car) {
    if (car == 0) {
      result.push_back(st.top());
      st.pop();
    } else {
      st.push(car);
    }
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  for (int i = 0; i < st.size(); i++) {
    cout << st.top() << endl;
    st.pop();
  }
  return 0;
}

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

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

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

int main()
{
	while(true)
	{
	vector<int>a;
	vector<int>b;
	vector<int>c;
	int s[20];

for(int i=0;i<20;i++)
{
	cin>>s[i];

if(s[i]==0)
	{
		b.push_back(s[i]);
		a.push_back(c.back());
		c.pop_back();
		if(c.size()==0)
		{
		break;
		}
	}
	else
	{
		c.push_back(s[i]);
	}
	
}
for(int j=0;j<a.size();j++)cout<<a[j]<<endl;
	}
return 0;


}

C++: #include<bits/stdc++.h>
using namespace std;
stack<int> s;
signed main(void){
	ios::sync_with_stdio(false);
	int x;
	while(cin>>x){
		if(x)
			s.push(x);
		else{
			cout<<s.top()<<endl;
			s.pop();
		}
	}
}

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

using namespace std;

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

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

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

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

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

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

using namespace std;

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

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

int main()
{
	int n;
	int pop_car[1024];
	int cnt = 0;
	stack<int> car;

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

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

	return (0);
}

C++: #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
  int car[10],car2[10]={0};
  stack<int> rail;
  int i=0,j=0;
  while(cin >> car[i]){
    if(car[i] != 0){
      rail.push(car[i]);
	}
    else{
      car2[j]=rail.top();
      rail.pop();
      j++;
    }
    i++;
  }
  for(i=0;i<j;i++){
    cout << car2[i] << endl;
  }
}

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

int main(){

  vector<int> vc;
  int n;

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

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cstring>

using namespace std;

int main(){
	stack<int> garage;
	vector<int> out;
	int enter;
	while(cin >> enter){
		if(enter == 0){
			out.push_back(garage.top());
			garage.pop();
		}
		else{
			garage.push(enter);
		}
	}

	for(vector<int>::iterator it = out.begin(); it != out.end(); it++){
		cout << *it << endl; 
	}

	return 0;
}

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

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> a;
  queue<int> ans;
  int box;
  while(1){
    cin >> box;
    if(box){
      a.push(box);
    }else{
      ans.push(a.top());
      a.pop();
    }
    if(a.empty())break;
  }
  while(1){
    cout << ans.front() << endl;
    ans.pop();
    if(ans.empty())break;
  }
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main( void )
{
  int d;
  stack<int> s;
  while( 1 ){
    cin >> d;
    if( cin.eof() ) break;
    if( d ) s.push( d );
    else { cout << s.top() << endl; s.pop(); }
  }
  return 0;
}