Go: package main

import "fmt"

func main() {
	var i int
	stack := make([]int, 0)
	for {
		v, _ := fmt.Scan(&i)
		// fmt.Println(stack)
		// println(v)
		if v == 0 {
			break
		}
		if i == 0 {
			fmt.Println(stack[len(stack)-1])
			stack = stack[:len(stack)-1]
			continue
		}
		stack = append(stack, i)
	}
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <istream>
#include <iomanip>
 
#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif


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

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

#if INPUT_FROM_FILE
	while(std::getline(ifs, buf)){
#else
	while(std::getline(std::cin, buf)){
#endif
		int n = std::stoi(buf);

		if(n != 0){
			stack.push_back(n);
		}
		else{
			std::cout << stack.back() << std::endl;
			stack.pop_back();
		}
	}
	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();
    }else{
      push(num);
    }
    if(size() == 0) break;
  }
  return 0;
}

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

int main(){
	vector<int> car, exit;
	int n;
	
	while( cin >> n ){
		
		if(n==0){
			exit.push_back( car.back());
			car.pop_back();
		}else{
			car.push_back(n);
		}
		if(car.size()==0) break;
	}
	vector<int>::iterator it = exit.begin();

	while( it != exit.end() ){
		cout << *it << endl;
		++it;
	}
	return 0;
}

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

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

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

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

int main()
{
	vector<int> train;
	for (int i = 0, n; i < 10 && cin >> n;) {
		switch (n) {
		case 0:
			cout << train.back() << endl;
			train.pop_back();
			i++;
			break;
		default:
			train.push_back(n);
		}
	}
	return 0;
}

C++: #include<stdio.h>
int i=0,j=0;
int cars[19];

int main(){
    while(1)
    {

        if(scanf("%d",&cars[i])==-1)
        {
            break;
        }
        if(cars[i]==0){
            printf("%d\n",cars[i-1]);
            i--;
        }
        else
        {
            i++;
        }
    }
    return 0;
}

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

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

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(i=l;i<n;i++)
using namespace std;

int main(){
	int data[15]={},i=0,n;

	while(1){
		cin>>n;
		if(n!=0){
			data[i]=n;
			i++;
		}else if(n==0){
			cout<<data[i-1]<<endl;
			i--;
		}
	}
}

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

int main()
{
	stack<int> car;
	vector<int> outlist;

	while( !car.empty() || outlist.empty() )
	{
		int carnum;
		cin >> carnum;
		if(carnum)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}
	
	cout << outlist[i] << '\n';
	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<stack>
#include<algorithm>
using namespace std;
int main(void){
    int j=0;
	int k;
	int b[1000]={0};
	stack<int> a;
	a.push(-1);
	for(int i=0;;i++){
        if(i>=1&&a.top()==-1)break;
        cin>>k;

        if(k==0){
            b[j]=a.top();
            j++;
            a.pop();
        }
        else a.push(k);
	}
	for(int i=0;i<j;i++){
        cout<<b[i]<<endl;
	}


	return 0;
}

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

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

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>


using namespace std;

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

	return 0;
}

C++: #include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp= 0;

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<stdio.h>
#include<math.h>
#include<stack>
int main(){
    using namespace std;
    stack <int>S;
    int a;
    while(~scanf("%d",&a)){
        if(a==0){
            printf("%d\n",S.top());
            S.pop();
        }
        else{
            S.push(a);
        }
    }
}

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

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

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

using namespace std;

int main()
{
	stack<int> hako;
	int temp[100];
	int t, i = 0;
	
	cin >> t;
	
	hako.push(t);
	while(hako.size() != 0){
		cin >> t;
		if(t == 0){
			temp[i] = hako.top();
			hako.pop();
			i++;
		}
		else{
			hako.push(t);
		}
	}
	
	for(int j = 0; j < i; j++){
		cout << temp[j] << endl;
	}
	
}

C++: #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <queue>
#include <vector>

using namespace std;

int main() {
  int i = 0, x, s[10];
  while (scanf("%d", &x) == 1)
    if (!x)
      printf("%d\n", s[--i]);
    else
      s[i++] = x;
  return 0;
}

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

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

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

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

using namespace std;

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

C++: #include<iostream>

using namespace std;

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

C++: #include<iostream>int main(){int a,c=0,s[12];while(std::cin>>a){if(a!=0)s[c++]=a;else std::cout<<s[--c]<<"\n";}return 0;}