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 <stack>
using namespace std;

int main(){
	int n,i,count = 0,x = 0,put[10];
	stack<int> get;
	while(1){
		cin >> n;
		if(n==0){
			put[x] = get.top();
			get.pop();
			count -= 1;
			x += 1;
		}
		else{
			get.push(n);
			count += 1;
		}
		if(count == 0) break;
	}
	for(i=0;i<x;i++){
		cout << put[i] << endl;
	}
	return 0;
}

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

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

int main(void)
{
    std::stack<int> n;
    int m;

    while(std::cin >> m)
    {
        if(m == 0)
        {
            std::cout << n.top() << std::endl;
            n.pop();
        }

        else
        {
            n.push(m);
        }
    }

    return 0;
}

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

using namespace std;

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

C++: // includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  vector<int> vec;
  while(cin >> n){
    if(n != 0)vec.pb(n);
    else{
      cout << vec[vec.size() - 1] << endl;
      vec.pop_back();
    }
  }
	return 0;
}

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

stack<int> st;

int main() {
	
	int m, tmp;
	
		
		for(;;)  {
			cin >> m;
			if(m > 0)  {
				st.push(m);
			}
			else if(m == 0)  {
				cout << st.top() << endl;
				st.pop();
				if( st.empty())
				return 0; 
			}
		}	
	return 0;
}

C++: #include <stdio.h>

int main() {
	int a,i,k,m;
	int data[15] = {0};
	int output[15] = {0};
	for (i = 0; i < 15; i++) {
		scanf("%d", &a);
		if (a != 0) {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					data[k] = a;
					break;
				}
			}
		}
		else {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					for (m = 0; m < 15; m++) {
						if (output[m] == 0) {
							output[m] = data[k - 1];
							break;
						}
					}
					data[k - 1] = 0;
					break;
				}
			}
		}
		if (data[0] == 0) {
			break;
		}
	}
	for (i = 0; i < 15; i++) {
		if (output[i] != 0) {
			printf("%d\n", output[i]);
		}
	}
	return 0;
}

C++: #include <stdio.h>

int main(){
	int i=0, j=0, num;
	int a[20], b[20];
	for(int i=0 ; i<20 ; i++){
		a[i] = 0;b[i]=0;
	}
	
	while( scanf("%d", &num) != EOF ){
		if(num==0){
			b[j] = a[i-1];
			j++;
			i--;
		}else{
			a[i] = num;
			i++;
		}
	}
	for(int n=0; n<j ; n++){
		printf("%d\n", b[n]);
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <iomanip>

using namespace std;


int main(void)
{
	int a[100], g = 0,co = 0;

	while (cin >> g)
	{
		if (g != 0)
		{
			co++;
			a[co] = g;
		}
		else
		{
			cout << a[co] << endl;
			a[co] = 0;
			co--;
		}
	}
	return 0;
}

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

using namespace std;

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

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

int main(){
	int a;
	std::stack<int> stack;

	while(std::cin >> a){
		if(a > 0){
			stack.push(a);		//push
		} else{
			std::cout << stack.top() << std::endl;	//表示
			stack.pop();		//pop
		}
	}

	return 0;
}

C++: #include<stdio.h>
#include<stack>

int main(){
	int i=0;
	std::stack<int> train;
	scanf("%d",&i);
	train.push(i);
	while(1){
		scanf("%d",&i);
		if(i==0){
			printf("%d\n",train.top());
			train.pop();
		}else{
			printf("%d\n",train.top());
			train.pop();
			train.push(i);
		}
	}
	return 0;
}

C++: #include <stdio.h>  

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

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

int main(){
	int num;
	stack<int> s;
	cin >> num;
	if(num!=0){
		s.push(num);
	}
	while(!s.empty()){
		cin >> num;
		if(num!=0){
			s.push(num);
		}
		else{
			cout << s.top() << "\n";
			s.pop();
		}
	}
	return 0;
}

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>
using namespace std;
int main(){
  
  int a[10],c=0,num;

  while(1){

    cin >>num;

    if(num >= 1 && num <=10){
      a[c]=num;
      c++;
    }else{
      cout <<a[c-1]<<endl;
      c--;
    }   

  }
  return 0;

}

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 <cstdlib>
#include<list>
#include<string>
#include<stack>
using namespace std;
int main(){
	int a;
	stack <int> b;
	while (cin >> a) {
		if (a != 0) {
			b.push(a);
		}
		else {
			cout << b.top() << endl;
			b.pop();
		}
	}
    return 0;
}

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

using namespace std;

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

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

stack<int> st;

int main() {
	for(int p; cin >> p;) {
		if(p == 0) {
			printf("%d\n", st.top());
			st.pop();
		} else {
			st.push(p);
		}
	}
	return 0;
}