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>
#include <vector>

using namespace std;

int main()
{
	int n;
	vector<int> train;
	while (cin >> n) {
		if (n) {
			train.push_back(n);
		}
		else {
			cout << train.back() << endl;
			train.pop_back();
		}
	}
	return 0;
}

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

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

C++: const int N=10;
using namespace std;


int main(){
    int a[N];
    int n=0;
    while (!cin.eof()){
        int t;
        cin>>t;
        if (t) a[n++]=t;
        else cout<<a[--n]<<endl;
    }
    return 0;
}

C++: //↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


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

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() << endl;
			s.pop();
		}
	}
	return 0;
}

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

int main() {
  stack<int> c;
  queue<int> q;

  int n;
  while(cin >> n) {
    if(n == 0) {
      int s = c.top();
      q.push(s);
      c.pop();
    }else {
      c.push(n);
    }
  }

  while(!q.empty()) {
    cout << q.front() << endl;
    q.pop();
  }

  return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

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

C++: // -*- coding: utf-8 -*-
// Last-Updated : <2014/06/19 18:20:36 by samui>

#include <iostream>
#include <cstdio>
#include <string>

#include <vector>

int main(int argc, char **argv){
  int a;
  std::vector<int> b;
  while(std::cin >>a){
    if(a == 0){
      std::cout<<b[b.size()-1]<<std::endl;
      b.pop_back();
    }else{
      b.push_back(a);
    }

  }
  return 0;
}

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

using namespace std;

int main() {
    stack<int> q;
    while (true) {
        int n;
        if (scanf("%d", &n) == EOF)
            break;

        if (n) {
            q.push(n);
        } else {
            printf("%d\n", q.top());
            q.pop();
        }
    }

    return 0;
}

C++: #include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp= 0;

int size(){
 return sp;
}

int top(){ return data[sp-1];
}
void pop(){
 sp--;
}

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

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

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

int main()
{
	stack<int> s;
	deque<int> ans;
	int n;

	while (1)
	{
		cin >> n;
		if (n == 0)
		{
			ans.push_front(s.top());
			s.pop();
			if (s.empty()) break;
		}
		else
		{
			s.push(n);
		}
	}

	while (1)
	{
		if (!ans.empty())
		{
			cout << ans.back() << endl;
			ans.pop_back();
		}
		else break;
	}
	return 0;
}

C++: /*
 * Problem     : AOJ0013
 * Title       : Switching Railroad Cars
 * Author      : mizo0203
 * Copyright   : Your copyright free
 * Description : スタック
 */

#include <stdio.h>
#include <stack>
using namespace std;

int cn; // car number or 0
stack<int> st;

bool input() {

  if (scanf("%d", &cn) == EOF)
    return false;

  return true;
}

int main() {

  while (input()) {
    if (cn) st.push(cn);
    else {
      printf("%d\n", st.top());
      st.pop();
    }
  }

  return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main()
{
	int n;
	stack<int> train;
	while(cin >> n){
		if(n) train.push(n);
		else {
			cout << train.top() << endl;
			train.pop();
		}
	}
	return 0;
}

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

int main()
{
	stack<int> CarEntrance;
	while(true){
		int CarNumber;
		cin >> CarNumber;
		if(cin.eof() == true) break;
		if(CarNumber == 0){
			cout << CarEntrance.top() << endl;
			CarEntrance.pop();
		}else{
			CarEntrance.push(CarNumber);
		}
	}
	return 0;
}

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

using namespace std;

stack<int>s;

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

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

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

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

int main()
{
        queue<int> op;
        queue<int> carrec;
        stack<int> car;
        int ops;
        int reccar;

        while(cin >> ops){
                op.push(ops);
        }

        while(!op.empty()){
                ops = op.front(); op.pop();
                if(ops != 0){
                        car.push(ops);
                }else if(ops == 0){
                        reccar = car.top();
                        carrec.push(reccar);
                        car.pop();
                }
        }

        while(!carrec.empty()){
                cout << carrec.front() << endl;
                carrec.pop();
        }

        return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>
#include <stack>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int in;
  stack<int> s;

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

  return 0;
}