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++: #include<iostream>
#include<stack>


int main(){
    using namespace std;

    stack<int>s;
    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 <cstdio>
#include <stack>

using namespace std;

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

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

int main(void) {
    int stack[100];
    int tail = 0;
    int n;
    while(cin >> n) {
        if(n) {
            stack[tail++] = n;
        } else {
            cout << stack[--tail] << endl;
        }
    }
}

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

using namespace std;

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

C++: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<stack>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int in;
  stack<int>out;
  while(cin>>in){
    if(in)out.push(in);
    else {
      cout<<out.top()<<endl;
      out.pop();
    }
  }


}

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

int main(){
   int a[10] = {}, n, poi;
   while(cin >> n){
     if(n == 0){
       cout << a[9] << endl;
       for(int i = 9;i > 0;--i){
           a[i] = a[i - 1];
          }
     }else{
       for(int i = 0;i < 9;++i){
           a[i] = a[i + 1];
       }
       a[9] = n;
     }
   }
  return 0;
}

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

using namespace std;

stack<int> Stack;

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<cfloat>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P; /* ツ点 */

#define PI (3.1415926535)
#define EPS (1e-10)

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

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

int main(void) {
    stack<int> unforwardable;
    vector<int> output;
    int car;
    while(cin >> car) {
        if(car == 0) {
            output.push_back(unforwardable.top());
            unforwardable.pop();
        } else {
            unforwardable.push(car);
        }
    }
    vector<int>::iterator ite;
    for(ite = output.begin(); ite != output.end(); ite++) {
        cout << *ite << endl;
    }
    return(0);
}

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

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

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>

using namespace std;

int main(){
	string code;
	string train;
	int i,j;

	while(cin >> code){
		if(code == "10") code = 'A';

		if(code == "0"){
			if(train[train.size()-1] == 'A'){
				cout << "10" << endl;
			}else{
				cout << train[train.size()-1] << endl;
			}
			string temp;
			for(i=0 ; i<train.size()-1 ; i++){
				temp += train[i];
			}
			train = temp;
		}else{
			train += code;
		}
	}

}

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

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

C++: #include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<int> line;
	int code;
	while (1) {
		cin >> code;
		if (code != 0) {
			line.push_back(code);
		}
		else {
			cout << *(line.end() - 1) << endl;
			line.pop_back();
		}
	}
	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 <cstdio>
#include <stack>
#define FOR(variable,a,b) for(variable=(a);variable<(b);variable++)

using namespace std;

int main() {
    // import phase
    int target;
    stack<int> map;
    
    // calculate phase
    while(scanf("%d", &target) != EOF) {
        if(target != 0) {
            map.push(target);
        } else {
            printf("%d\n", map.top());
            map.pop();
        }
    }

    return 0;
}

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

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