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++: #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;
}

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

int main()
{
	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<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
  stack<int> st;
  int d;
  do {
    cin >> d;
    if(d == 0){
      cout << st.top() << endl;
      st.pop(  );
    }else {
      st.push( d );
    }
  }while(!st.empty());
}

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

using namespace std;

int main()
{
	deque<int> st;
	int n;
	while(cin >>n){
		if(n){
			st.push_back(n);
		}else{ // 0が入力されたとき
			cout << st.back() << endl;
			st.pop_back();
		}
	}
	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(void){
	int num;
	stack<int> st;

	while(1){
		cin>>num;
		st.push(num);
		if(num==0){
			st.pop();//0ツづーツ渉慊つュ
			cout<<st.top()<<endl;
			st.pop();
		}
	}
	return 0;
}

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

int main()
{
	int line,i=0,stack[10] = {0};

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

	return 0;
}

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() {
  stack<int> s;
  int n;
  while(cin>>n) {
    if(n==0){
      cout<<s.top()<<endl;
      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(0<n) st.push(n);
		else
		{
			cout<<st.top();
			st.pop();
		}
	}
	return 0;
}

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

int main(){
	int rail[11];
	int num=0;
	while(true){
		int now;
		cin >> now;
		if(cin.eof())
			break;
		else if(now ==0){
			cout << rail[num] << endl;
			num--;
		}
		else{
			num++;
			rail[num] = now;
		}
	
	}
	return 0;

}

C++: #include<stdio.h>
int main(){
int a[100];
int j;
for(int i=0;;i++){
scanf("%d",&a[i]);
if(a[i]==0){
j=i;
while(){
if(j1!=0){
printf("%d",a[j1]);
break;
}
j--;
}
}
}

C++: #include <iostream>

#include <stack>

using namespace std;

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

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

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

// Switching Railroad Cars(0013)
int main()
{
	int n;
	stack<int> train;
	while (cin >> n) {
		if (n == 0) {
			cout << train.top() << endl;
			train.pop();
		} else {
			train.push(n);
		}
	}
	return 0;
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){

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

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

int main(){

  int n;
  stack <int> a;

  while(cin >> n){

    if(n==0){
      cout << a.top() << endl;
      a.pop();
    }

    else a.push(n);
  }
}

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

int a;
stack<int> s;

int main() {
	while (scanf("%d",&a) != EOF) {
		if (a==0) {
			printf("%d\n",s.top());
			s.pop();
		}
		else s.push(a);
	}
}

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<100;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 <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define INF 1<<25
#define LIM 1000000

using namespace std;

stack<int> st;
queue<int> qu;

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

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

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

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

int main() {
	int n, count = 0, a[11], i;
	stack<int> s;
	while (cin >> n,n>=0,!cin.eof()) {
		if (n > 0) s.push(n);
		else if (n == 0) { a[count++] = s.top(); s.pop(); }
	}
	for (i = 0; i < count; i++) {
		cout << a[i] << endl;
	}
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int> line,ans;
	int pro;
	while(1)
	{
		cin>>pro;
		if(pro!=0){
			line.push_back(pro);
		}else{
			ans.push_back(*(line.end()-1));
			line.erase(line.end()-1);
		}
		if(line.empty())break;
	}
	vector<int>::iterator it;
	for(it=ans.begin();it!=ans.end();++it)
	{
		cout<<*it<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int a[10];
	int b[10];
	int c;
	int i=0;
	int t=0;	
	do{
		scanf_s("%d",&c);
		if (c >= 1 && c <= 10){	
			a[t] = c;			
			t++;				
		}
		else if (c == 0){		
			t--;		
			b[i] = a[t];	
			i++;
			
		}

	} while (t > 0);	

	printf("\n");
	for (c = 0; c < i; c++){	
		printf("%d\n",b[c]);
	}
	return 0;
}