Go: package main

import (
        "fmt"
)

func main() {
        var stk [101]int
        var c int
        pvt := 0
        for {
                _, err := fmt.Scanf("%d", &c)
                if err != nil {
                        break
                }
                if c > 0 {
                        stk[pvt] = c
                        pvt++
                } else {
                        pvt--
                        fmt.Printf("%d\n", stk[pvt])
                }
        }
}

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


int main(){

  int train[10] , num[10];

 for( int i = 0; i < 10; i++ ){
    train[i] = 0;
    num[i] = 0;
 }

  for( int i = 0; i < 10; i++ ){

    cin >> train[i];

    if( train[i] == 0 ){
      for( int j = i; j >= 0; j-- ){
	if( train[j] != 0 ){
	num[i] = train[j];
	train[j] = 0;
	break;
	}
      }
    }
  }
  

  for( int k = 0; k < 10; k++ ){
    if( num[k] != 0 ) cout << num[k] << endl; 

  }


  return 0;
}

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

//????°?????????\???????????§back?????????????????????
int main() {
    int n;
    list<int> l={0};
    while (scanf("%d",&n)!=EOF) {
        if (n==0) {
            printf("%d\n",l.front());
            l.pop_front();
        } else {
            l.push_front(n);
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <math.h>
#include <string>
#include <cmath>
#include <iomanip>

int main();


int main(){
	std::stack<int> input;		//入力される数（車両番号）を格納する
	std::vector<int> output;	//出力される車両番号
	int dummy = 0;				//ダミーナンバー
	int count = 0;

	//while (count < 8){
		//std::cin >> dummy;
		//count++;
	while (std::cin >> dummy){
		if ((dummy == 0) && (!input.empty())){
			output.push_back(input.top());
			input.pop();
		}
		else if((1 <= dummy) && (dummy <= 10)){
			input.push(dummy);
		}
		else{
			//何もしない
		}
	}

	for (int i = 0; i < output.size(); i++){
		std::cout << output[i] << std::endl;
	}

	//while (1);
	return 0;
}

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

int a[11];
int b, t;

int main() {
  cin>>a[0];
  t=1;
  
  while(t>1) {
    cin>>b;
    if(b>0) {
      a[t]=b;
      t++;
    }else {
      cout<<a[t-1]<<endl;
      t--;
    }
  }
  
  return 0;
}

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

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

using namespace std;

int main(){
    int c, num;
    stack <int> s;
    while(1){
        cin >> num;
        if(!num){
            if(!c) break;
            else{
                cout << s.top() <<endl;
                s.pop();
            }
        }
        else{
            if(c==10) cout << "Already Full" <<endl;
            else s.push(num);
        }
    }
    return 0;
}

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

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	stack<int> s;
	int n;
	while(scanf("%d",&n)!=EOF){
		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> s;
	while (true) {
		cin >> n;

		if (n == 0) {
			cout << s.top() << endl;
			s.pop();
		}
		else {
			s.push(n);
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>

using namespace std;

typedef complex<double> P;

int main(){

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

	return 0;
}

C++: #include <stdio.h>

int train[10];
int sp = 0;

int empty() {
  return sp <= 0;
}

int size() {
  return sp;
}

int top() {
  return train[sp-1];
}

void pop() {
  sp--;
}

void push(int v) {
  train[sp] = v;
  sp++;
}

int main(){
  int out[10];
  int num, i = 0;
  while(1){
    scanf("%d", &num);
    if(num == 0){
      out[i] = top();
      i++;
      pop();
    }else if(1 <= num && num <= 10){
      push(num);
    }
    if(size() == 0) break;
  }
  for(i = 0; i < 10; i++){
    printf("%d\n", out[i]);
  }
  return 0;
}

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

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

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

int main()
{
	int n;
	vector<int> cars;
	vector<int> order;
	while (cin >> n) {
		if (n==0)  {
			order.push_back(cars.back());
			cars.pop_back();
		}
		else
			cars.push_back(n);
		if (cars.size() == 0)
			break;
	}

	for (int i=0;i<order.size();i++)
		cout << order[i] << endl;

	return 0;
}

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

int main(){

  std::stack<int> st;

  int N = 0;
  int a;

  while(N <= 100 && std::cin >> a){
    if(a != 0){
      st.push(a);
    }
    else{
      std::cout << st.top() << std::endl;
      st.pop();
	}
    ++N;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

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

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	stack<int> S;
	int n;
	cin >> n;
	S.push(n);
	vi ans;
	while(!S.empty()) {
		cin >> n;
		if(n) {
			S.push(n);
		} else {
			ans.push_back(S.top());
			S.pop();
		}
	}
	
	REP(i, ans.size()) {
		cout << ans[i] << endl;
	}
	return 0;
}