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

C++: #include <stdio.h>

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

C++: #include <iostream>
#include <stack>
#include <vector>
int main(){
  std::stack<int> i;
  std::vector<int> o;
  int n;
  while(std::cin>>n){
    if(!n)o.push_back(i.top()),i.pop();
    else{i.push(n);}
    if(i.empty()&&!o.empty())break;
  }
  std::vector<int>::iterator it = o.begin();
  while(it!=o.end()){
    std::cout<<*it<<std::endl;
    it++;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int now=-1;
	int n[10]={0};
	int in;
	for(;;){
		cin>>in;
		if(in==0){
			cout<<n[now];
			now--;
			if(now==-1)return 0;
		}
		else{
			n[now+1]=in;
			now++;
		}
	}
}

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;
}