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<stdio.h>
int main(void){
	char tr[30];
	int i=0,k,l,in[10]={ 0 },out[10]={ 0 };
	for(k=-1,l=0;;i++){
		scanf("%d",&tr[i]);
		switch(tr[i]){
			case 1:
				k++;
				in[k]=1;
				break;
			case 2:
				k++;
				in[k]=2;
				break;
			case 3:
				k++;
				in[k]=3;
				break;
			case 4:
				k++;
				in[k]=4;
				break;
			case 5:
				k++;
				in[k]=5;
				break;
			case 6:
				k++;
				in[k]=6;
				break;
			case 7:
				k++;
				in[k]=7;
				break;
			case 8:
				k++;
				in[k]=8;
				break;
			case 9:
				k++;
				in[k]=9;
				break;
			case 10:
				k++;
				in[k]=10;
				break;
			case 0:
				out[l]=in[k];
				in[k]=0;
				k--;
				l++;
				break;
			default :
				break;
		}
		if(in[0]==0){break;}
	}
	for(i=0;i<l;i++){
		printf("%d\n",out[i]);
	}
	return 0;
}

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

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

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


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

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

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

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
vector<int> vec;

int main() {

	while(1){
		int n;
		cin>>n;
		if(cin.eof())break;
		if(n==0){
			cout<<vec[vec.size()-1]<<endl;
			vec.pop_back();
		}else vec.push_back(n);
	}

	return 0;
}

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

int main ()
{
    std::stack<u_int> cars;
    u_int number;

    while(std::cin >> number){
        if(number != 0){
            cars.push(number);
        }else{
            std::cout << cars.top() << std::endl;
            cars.pop();
        }
    }
    
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <complex>
#include <iterator>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i, a, cont, next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i, a, b, step) repfn(i, a, i < b, i + step)
#define repab(i, a, b) repby(i, (a), (b), 1)
#define rep(i, n) repab(i, 0, (n))
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  stack<int> s;
  int tmp;
  while (cin >> tmp) {
    if (tmp)
      s.push(tmp);
    else {
      cout << s.top() << endl;
      s.pop();
    }
  }
  return 0;
}

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

using namespace std;

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

    return 0;
}

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

using namespace std;

int main() {
  stack<int> cars;
  string line;
  while (getline(cin, line)) {
    int car = atoi(line.c_str());
    if (car == 0) {
      cout << cars.top() << endl;
      cars.pop();
    } else {
      cars.push(car);
    }
  }

  return 0;
}

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

int main(){
	int a[100];
	int i = 0;

	while (1){
		cin >> a[i];
		if (a[i] == 0){
			int j = i;
			while (1){
				j--;
				if (a[j] != 0){
					cout << a[j] << endl;
					a[j] = 0;
					break;
				}
			}
		}
		i++;
	}


	return 0;
}

C++: #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<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

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

C++: #include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#define INF 100000000
 
using namespace std;
typedef long long ll;

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

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

int main(){
    std::stack<int> rail;
    int buf;
    
    // repeat until "cin" fails.
    while (std::cin >> buf) {
        if (buf == 0) { // train goes out.
            std::cout << rail.top() << std::endl;
            rail.pop();
        }
        else{   // train comes in.
            rail.push(buf);
        }
    }
    
    return 0;
}

C++: #include<stdio.h>
#include<stack>
using namespace std;
int main(){
	stack<int>cars;
	int i;
	while(~scanf("%d",&i)){
		if(i==0){
			printf("%d\n",cars.top());
			cars.pop();}
		else cars.push(i);}
	return 0;}

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

using namespace std;

int main(){
    int num;
    stack <int> s;
    while(1){
        cin >> num;
        if(!num){
            if (s.empty()) break;
            cout << s.top() <<endl;
            s.pop();
        }
        else s.push(num);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
	vector<int> v(10);
	int n, j = 0;
	while (cin >> n) {
		if (n) {
			v.at(j) = n;
			j++;
		}
		else {
			j--;
			cout << v.at(j) << endl;
			v.at(j) = 0;
		}
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
	int a[10], num;
	int count = 0;

	while(cin >> num){
		if(num != 0){
			a[count] = num;
			count++;
		}
		else{
			cout << a[count - 1] << endl;
			count--;
		}
	}

	return 0;
}