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

int main()
{
	std::vector<int> cars;
	int input;
	while (std::cin >> input) {
		if (input != 0) {
			cars.push_back(input);
		} else if (!cars.empty()) {
			std::cout << cars.back() << std::endl;
			cars.pop_back();
		}
	}

	return 0;
}

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

using namespace std;

int main(){
  deque<int> que;
  int n;
  while(~scanf("%d",&n)){
    if(n){
      que.push_back(n);
    }else{
      printf("%d\n",que.back());
      que.pop_back();
    }
  }
}

C++: #include <stack>

#include <stdio.h>

int main(int argc, char** argv)
{
  std::stack<int> stack;

  int i;

  while (fscanf(stdin, "%d", &i) == 1) {
    if (i) {
      stack.push(i);
    }
    else {
      fprintf(stdout, "%d\n", stack.top());
      
      stack.pop();
    }
  }
}

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

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    long long int n;
    std::stack<long long int> s;

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

    return 0;
}

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

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

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n[100],k;
	
	k=0;
	while(cin >> n[k]){
		if(n[k]==0){
			cout << n[k-1] << "\n";
			k--;
		}
		else{
			k++;
		}
	}
		
return 0;
}

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

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

using namespace std;

int main(){

  int train;
  stack<int> s;

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

}

C++: //C++ツづ可偲?堕閉つウツづェツづ?つ「ツづゥツスツタツッツクツづーツ使ツつヲツづ篠甘按単
#include <iostream>
#include <stack>
using namespace std;

int main(){
  int n;
  stack<int> st;

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

C++: #include <iostream>

using namespace std;

int main(){
  short stack[10]={0},turn[10]={0};
  short *pstack=stack,*pturn=turn;
  while(1){
    int num;
    cin>>num;
    if(num){
      *pstack=num;
      pstack++;
    }else{
      pstack--;
      *pturn=*pstack;
      pturn++;
    }
    if(pstack==stack) break;
  }
  for(pturn=turn;*pturn;pturn++)
    cout<<*pturn<<endl;
}

C++: #include<stdio.h>
int main(void)
{
	int n,s[100],i=0;
	while(scanf("%d",&s[i])!=EOF){
		if(s[i]==0){
			i--;
			printf("%d\n",s[i]);
		}
		else {
			i++;
		}
	}
	return 0;
}

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

int main(){
	stack<int> st;
	int n, a;

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

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

using namespace std;

int main() {

	stack<int> st;
	int a, ans[100]={0},i = 0;

	while (1) {
		cin >> a;
		if (a == 0) {
			ans[i] = st.top();
			st.pop();
			i++;
			if (st.empty())
				break;
		}
		else {
			st.push(a);
		}
	}

	for (int j = 0; j < i; j++) {
		cout << ans[j] << endl;
	}

	return 0;
}

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

using namespace std;
int main(int ac, char **av) {
  stack<int> st;
  int t;

  while (cin >> t) {
    if (t == 0) {
      cout << st.top() << endl;
      st.pop();
    } else {
      st.push(t);
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int b[1000000];
int main(){
  int i=0,num,a[10],x=0;
  
  while(cin>>num){
    if(num==0){
      b[x++]=a[i-1];
      i--;
    }
    else  a[i++]=num;
    if(!i)break;
  }
  
  for(i=0;i<x;i++)
    cout<<b[i]<<endl;
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    int a;
    vector<int> s;
    vector<int> t;
    while(cin>>a){
        if(a!=0){
            s.push_back(a);
        }else{
            s.pop_back(a);
            t.push_back(s[s.size()-1]);
            s.pop_back(s[s.size()-1]);
        }
    }
    for(int i=0;i<t.size();i++){
        cout << t[i] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
int main() {
	int num, retu=0;
		int *train = new int[10];
		while (cin >> num) {
			if (num == 0) {
				cout << train[retu-1]<<endl;
				retu--;
			}
			else {
				train[retu] = num;
					retu++;
			}
	}
	return 0;
}

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

int main( void )
{
	stack <int> S;
	int first;
	cin >> first;
	S.push( first );

	string kotae = "";
	while ( S.empty() == false )
	{
		int n;
		cin >> n;
		if ( n == 0 )
		{
			ostringstream os;
			os << S.top() << endl;
			kotae += os.str();
			S.pop();
		}
		else
		{
			S.push( n );
		}
	}

	cout << kotae << endl;

	return 0;
}

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


int main()
{
    std::stack<int> Stack;
    while(true){
        int n;
        std::cin >> n;
        if(n == 0){
            assert(Stack.empty() == false);
            std::cout << Stack.top() << std::endl;
            Stack.pop();
        }else{
            Stack.push(n);
        }
        if(std::cin.eof()) break;
    }
    return 0;
}

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

using namespace std;

int main() {
    int x;
    stack<int> stack;

    while (cin >> x) {
        if (!x) {
            cout << stack.top() << endl;
            stack.pop();
        } else {
            stack.push(x);
        } 
    }
}

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

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	vector<int>in;
	while(cin>>n){
		if(n)in.pb(n);
		else {
			cout<<in[in.size()-1]<<endl;
			in.erase(in.end()-1);
		}
	}
}

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

	return 0;
}