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++: //
//  main.cpp
//  BT
//
//  Created by h3037175 on 2017/07/27.
//  Copyright ?? 2017??´ h3037175. All rights reserved.
//

#include <iostream>
#include <stack>
using namespace std;
int main() {
    stack<int> st;int a;
    while(cin>>a){
        if(a==0){
            cout<<st.top()<<endl;
            st.pop();
        }
        else{
        st.push(a);
        }
    }
        return 0;
}

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

using namespace std;

int main(){

  vector<int> V;
  int in;
  while(cin >> in){
    if(in != 0) V.push_back(in);
    else{
      cout <<  V.back() << endl;
      V.pop_back();
    }
  }
  return 0;
}

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

int main()
{
	int N;
	stack<int> train;
	queue<int> leave;
	while (cin >> N) {
		if (N == 0) {
			leave.push(train.top());
			train.pop();
		}
		else {
			train.push(N);
		}
	}
	for (; leave.empty() == 0;) {
		cout << leave.front() << endl;
		leave.pop();
	}
	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 num;
  while(1){
    scanf("%d", &num);
    if(num == 0){
      printf("%d\n", top());
      pop();
      if(sp = 0) break;
    }else{
      push(num);
    }
  }
  return 0;
}

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

using namespace std;

int main() {
	int data[10];
	stack<int> line;
	vector<int> top;
	int i = 0;

	while (cin >> data[i]) {
		++i;
	}

	for (auto i : data) {
		if (i == 0) {
			top.push_back(line.top());
			line.pop();
		}
		else {
			line.push(i);
		}
	}

	for (auto t : top) {
		cout << t << endl;
	}

	return 0;
}

C++: #include <iostream>

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

C++: #include<iostream>
#include<stack>
#include<vector>
using namespace std;
stack<int>S; int a; vector<int>t;
int main() {
	cin >> a;
	S.push(a);
	while (cin >> a) {
		if (a == 0) {
			t.push_back(S.top());
			S.pop();
		}
		else {
			S.push(a);
		}
	}
	for (int i = 0; i < t.size(); i++) {
		cout << t[i] << endl;
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int main(){
	int k;
	stack<int> q;

	cin >> k;
	q.push(k);

	while (1){
		cin >> k;
		if (k != 0)
			q.push(k);
		else{
			printf("%d\n", q.top());
			q.pop();
		}
		if (q.empty())
			break;
	}
}

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

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num==0) pop();
		else push(num);
	}

    return 0;
}

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

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

	//car's number
	int num = 0;

    //Until the end of input
	while(std::cin >> num){
        //if num = 0, output and delete
		if(num == 0){
			std::cout << st.top() << std::endl;
			st.pop();
        //if num != 0, input    
		} else {
			st.push(num);
		}
	}
}

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

int car_n;
std::stack<int> st;

bool get_input()
{
	return (std::cin >> car_n);
}

int main()
{
	while (get_input()) {
		if (car_n == 0) {
			std::cout << st.top() << std::endl;
			st.pop();
		} else {
			st.push(car_n);
		}
	}
	return 0;
}

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

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

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){
	stack<int> stk;
	int a;
	
	while(cin>>a){
		if(a){
			stk.push(a);
		}else{
			cout<<stk.top()<<endl;
			stk.pop();
		}
	}

	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(5);
	solve();

	return 0;
}

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

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

	}
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int a;
  stack<int> st;
  while (cin >> a) {
    if (a == 0) {
      cout << st.top() << endl;
      st.pop();
    } else {
      st.emplace(a);
    }
  }

  return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  stack<int> chu;
  int i=0;
  int input;
  int hairetu[111];
  cin>>input;
  chu.push(input);
  while(cin>>input){
    if(input!=0){
      chu.push(input);
    }else{
      hairetu[i]=chu.top();
      chu.pop();
      i++;
    }
  }
  for(int j=0;j<=i-1;j++){
    cout<<hairetu[j]<<endl;
  }
  
}

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

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

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-6;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    int n;
    stack<int> q;
    while(cin>>n){
        if(n==0){
            cout<<q.top()<<endl;
            q.pop();
        }else{
            q.push(n);
        }
    }
}

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

int main(void)
{
	stack<int> car;
	int n;

	while(cin >> n) {
		if(n)
			car.push(n);
		else {
			cout << car.top() << endl;
			car.pop();
		}
	}

	return 0;
}