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 <algorithm>
#include <string>
#include <stack>
using namespace std;
int main(void) {
	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>
#include <stack>
#include <vector>

using namespace std;

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

    while (~scanf("%d", &input)){
        if (input==0){
            cout<<train_stack.top()<<endl;
            train_stack.pop();
        }
        else{
            train_stack.push(input);
        }
    }
    return 0;
}

C++: #include<cstdio>
#include<stack>
using namespace std;
int main(){
    int a;
    stack<int>car;
    while(scanf("%d",&a)!=EOF){
    if(a!=0){
        car.push(a);
    }
    else{
        int b=car.top();
        printf("%d\n",b);
        car.pop();
    }
    }
    return 0;
}

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

int main()
{
	int car[10],order[100],i,j,k=0;
	
	for(i=0; i<10; i++){car[i]=0;}
	i=0;
	while((scanf("%d",&order[i]))!=EOF){i++;}
	for(j=0; j<i; j++){
		if(order[j]!=0){
			car[k]=order[j];
			k++;
		}else{
			k--;
			cout << car[k] << endl;
			car[k]=0;
		}
	}
}

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

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

C++: #include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
	int N;
	stack<int> st;
	while( cin >> N )
	{
		if( N == 0 ){
			cout << st.top() << endl;
			st.pop();
			continue;
		}
		st.emplace( N );
	}
	return 0;
}

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

using namespace std;

int main() {

	int n;
	stack<int> line;

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

	return 0;
}

C++: #include<stdio.h>
int i=0,j=0;
int cars[19];

int main(){
    while(1)
    {

        if(scanf("%d",&cars[i])==-1)
        {
            break;
        }
        if(cars[i]==0){
            printf("%d\n",cars[i-1]);
            i--;
            j++;
        }
        else
        {
            i++;
        }
        if(j==10)
        {
            break;
        }
    }
    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() << endl;
			s.pop();
		}else{
			s.push(n);
		}
	}
	return 0;
}

C++: 
#include <stdio.h>

int train(int array[], int a)
{
	int i;
	for(i=0; i<10; i++)
	{
		if(array[i]==0)
		{
			if(a)
			{
				array[i]=a;
				return 0;
			}
			
			if(i>0 && a==0)
			{
				printf("%d\n", array[i-1]);
				array[i-1]=0;
				return 0;
			}
		}
	}
	return 0;
}
	

int main (void)
{
	int a, trains[10], i;
	
	for(i=0; i<10; i++)
	{
		trains[i]=0;
	}
	
	while(scanf("%d", &a)!=EOF)
	{
		train(trains, a);
	}
	
	return 0;
}

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

using namespace std;

int main()
{
	stack<int> trains;
	int n, c, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &c);
		if (c == 0)
		{
			printf("%d\n", trains.top());
			trains.pop();
		}
		else
			trains.push(c);
	}
	return 0;
}

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

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

C++: #include <stack>

int main(){
  std::stack<int>s;
  for(int x;~scanf("%d",&x);)
    if(x)s.push(x);
    else printf("%d\n",s.top()),s.pop();
}

C++: #include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF  2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d); BR;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a+n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    int s[100], top = 0, a;
    while(cin >> a){
        if(a){
            s[top++] = a;
        }else{
            OUTL(s[--top]);
        }
    }
RET;}

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

int main(){
	int stack[10];
	int s_num = 0;
	int x;

	while(cin >> x){
		if(x == 0){
			cout << stack[s_num-1] << endl;
			s_num --;
		}else{
			stack[s_num] = x;
			s_num ++;
		}
	}

	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>

int stack[100];
int point=0;

void push(int p){
	stack[point]=0;
	++point;
}

void pop(){
	std:cout << stack[point] << endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std:cin >> num;
		if(num==0) pop();
		else push(num);
	}

    return 0;
}

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

int main()
{
  int n, i = 0, j = 0;
  int car[10] = {1};
  int output[10];
  while(cin >> n){
    if(n == 0){
      output[j] = car[i - 1];
      car[i - 1] = 0;
      i--;
      j++;
    }else{
      car[i] = n;
      i++;
    }
  }
  for(int i = 0; i < j; i++){
    cout << output[i] << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main() {
  stack<int> s;
  vector<int> v;
  int n;
  while (cin >> n) {
    if (n == 0 && !s.empty()) {
      v.push_back(s.top());
      s.pop();
    } else {
      s.push(n);
    }
  }
  for (int i = 0; i < v.size(); ++i) {
    cout << v[i] << endl;
  }
  return 0;
}

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

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

  return 0;
}

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

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