Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	n, err := strconv.Atoi(nextString())
	return n, err
}

func main() {
	scanner.Split(bufio.ScanWords)

	stack := []int{}
	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		if n == 0 { // pop
			fmt.Println(stack[len(stack)-1])
			stack = stack[0:(len(stack) - 1)]
		} else { // push
			stack = append(stack, n)
		}
	}
}

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

int main() {
	int in;
	vector <int> a;
	while (1) {
		cin >> in;
		if (in == 0) {
			cout << a[a.size() - 1] << endl;
			a.erase(a.end() - 1);
			if (a.size() == 0)
				break;
		}
		else
			a.push_back(in);
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define PUSH intStackPush
#define POP intStackPop
#define TOP intStackTop
#define FREE intStackFree

typedef struct stack{ int data; struct stack* next; }stack;

stack *top = NULL;

stack* makeNewStack(int data){
  stack *new = (stack*)malloc(sizeof(stack));
  new->data = data;
  new->next = NULL;
  return new;
}

void intStackPush(int data){
  stack *new = makeNewStack(data);
  if(top != NULL){ new->next = top; top = new; }
  else top = new;
}

void intStackPop(){
  stack *temp;
  temp = top;
  top = top->next;
  free(temp);
}

int intStackTop(){ return top->data;}

void intStackFree(){ while(top != NULL) intStackPop();}

int main(){
  int in;

  while(scanf("%d", &in) != EOF){
    if(in == 0){
      printf("%d\n",TOP());
      POP();
    }
    else PUSH(in);
  }

  FREE();
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<stack>//?????????????????¢??°

using namespace std;

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

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

int main(void){
	int stack[10];
	int pt=0, n;
	while(cin >> n){
		if(n == 0) {
			cout << stack[pt-1] << endl;
			pt--;
		}
		else {
			stack[pt] = n;
			pt++;
		}
	}
	return 0;
}

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

int main(void){
  stack<int> car;
  int num,res[10000],cnt=0,cnt1=0;

  while( cin >> num ){

    if( num != 0 ) car.push(num);
    else{
      res[cnt] = car.top();
      car.pop();
      cnt++;
      cnt1++;
    }
  }

  cnt = 0;

  while(cnt1){

    cout << res[cnt] << endl; 
    cnt++;
    cnt1--;

  }

  return 0;
}

C++: #include <stdio.h>

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

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <stack>
using namespace std;
int main(){
  int n;
  stack<int> in,out;
  while(cin>>n){
    if(!n)out.push(in.top()),in.pop(),cout<<out.top()<<endl;
    else{in.push(n);}
    if(in.empty()&&!out.empty())return 0;
  }
}

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

int main(void)
{
	int car[20] = {0};
	int in = 0;

	while(car[0] != -1) {
		int n;
		cin >> n;
		car[in] = n;

		if(n == 0) {
			for(int i = in - 1; i >= 0; i--) {
				if(car[i] > 0) {
					cout << car[i] << endl;
					car[i] = -1;
					break;
				}
			}
		}

		in++;
	}
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(void){
    // Here your code !
    stack<int> s;
   for(int d;cin>>d;){
    
       if(d==0){
           cout<<s.top()<<endl;
           s.pop();}
       else{
           s.push(d);
       }
}
}

C++: #include<cstdio>
#include<cmath>
 
//#include<iostream>
using namespace std;
 
int main(){
int i=0, j, ar[11];

	while( scanf("%d" , &j)!= EOF){
		if(j!=0)	ar[++i]=j;
		else 		printf("%d\n",ar[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(1);
}

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

int main(){
  stack<int> car;
  int n,cou=0,i=0,ans[1111];
  while(cin >> n){
    if(n == 0){
      cout << car.top() << endl;
      car.pop();
    }
    else{
      car.push(n);
    }
  }
}

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

int main(){
	int n,count = 0;
	stack<int> get;
	while(1){
		cin >> n;
		if(n==0){
			cout <<  get.top() << endl;
			get.pop();
			count -= 1;
		}
		else{
			get.push(n);
			count += 1;
		}
		//if(count == 0) break;
	}
	return 0;
}

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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  stack<int> s;
  int n;
  while(cin>>n){
    if(n!=0)s.push(n);
    else{
      cout <<s.top() <<endl;s.pop();
    }
  }
  return 0;
}

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

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

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++){
		scanf("%d",&g);
		
		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;
		} 
		*/
	}
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main() {
	int a;
	vector<int>l;
	while (cin >> a){
		if (a == 0){
			cout << l.back()<<endl;
			l.pop_back();
		}else{
			l.push_back(a);
		}
	}
}

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

int main(){
	int n;
	stack<int> t;
	vector<int> a;
	while(cin>>n){
		if(n==0){
			a.push_back(t.top());
			t.pop();
		}
		else{
			t.push(n);
		}
	}
	for(int i=0;i<a.size();i++){
		cout<<a[i]<<endl;
	}
	return 0;
}

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

int main(){
	std::stack<int> in;
	std::queue<int> out;
	int num;
	
	while(std::cin >> num){
		if(num == 0){
			out.push(in.top());
			in.pop();
		}else
			in.push(num);
		
		//output
		if(in.empty()){
			while(!out.empty()){
				std::cout << out.front() << std::endl;
				out.pop();
			}
		}
	}
	
    return 0;
}

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

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

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

int main(){
	int a[100];
	int i = 0;

	for (int i = 0; i < 100; i++){
		a[i] = 0;
	}

	while (1){
		i++;
		cin >> a[i];
		if (a[i] == 0){
			int j = i+1;
			while (1){
				j--;
				if (a[j] != 0){
					cout << a[j] << endl;
					a[j] = 0;
					break;
				}
			}
		}
	}


	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く 
　　提出する問題を間違えない */
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
int main(){
  stack<int> train;
  int a;
  while(1){
    cin >> a;
    if(a){
      train.push(a);
    }else{
      if(cin.eof())break;
      cout << train.top() << endl;
      train.pop();
    }
  }
}