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<cstdio>
#include<cstring>
using namespace std;

int main(){
   int syako[999];
   int i=1;
   
   cin>>syako[0];
   while(i>0){
      cin>>syako[i];
      i++;
      if(syako[i-1] == 0){
         printf("%d\n",syako[i]);
         i-=2;
      }
   }
   return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int in[10] = {0},out[10];
	int n;
	int i = 0;
	int j = 0;
	while(scanf("%d",&n) != EOF){
		if(n != 0){
			in[i] = n;
			i++;
		}
		else {
			i--;
			out[j] = in[i];
			j++;
			in[i] = 0;
		}
	}
	
	for(int i = 0;i < j;i++){
		cout << out[i] << endl;
	}
}

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

int main() {
  stack<int> sta;
  
  while(1){
  
    int temp;
    cin >> temp;
    
    if (temp==0){
      if (sta.empty()==false){
	cout << sta.top() <<endl;
	sta.pop();
      }
    }else{
      sta.push(temp);
    }
  }
    
  return 0;
  
}

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

int main(){
  stack<int> st;
  int a;
  while(cin>>a){
    if(a)st.push(a);
    else {printf("%d\n",st.top());
      st.pop();
      if(st.empty())break;
}

   }
  return 0;
}

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

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

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

    return 0;
}

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

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

int main(){

  std::stack<int> st;

  int N = 0;
  int a;

  while(N <= 100 && std::cin >> a){
    if(a != 0){
      st.push(a);
    }
    else{
      std::cout << st.top() << std::endl;
      st.pop();
	}
    ++N;
  }
}

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

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

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

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

int main(){
	std::stack<int> garage;
	int vehicle_num; //railroad car
	
	while(std::cin >> vehicle_num){
		if(vehicle_num != 0) garage.push(vehicle_num);
		else{
			std::cout << garage.top() << std::endl;
			garage.pop();
		}
	}
	
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int in;
	vector <int> a;
	while (1) {
		cin >> in;
		if (in == 0) {
			cout << a[a.size() - 1];
			a.erase(a.end() - 1);
			if (a.size() == 0)
				break;
			else
				cout << endl;
		}
		else
			a.push_back(in);
	}
	return 0;
}

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

int main(){
	int n,i,count = 0,x = 0,put[10];
	stack<int> get;
	while(1){
		cin >> n;
		if(n==0){
			put[x] = get.top();
			get.pop();
			count -= 1;
			x += 1;
		}
		else{
			get.push(n);
			count += 1;
		}
		if(count == 0) break;
	}
	for(i=0;i<x;i++){
		cout << put[i] << endl;
	}
	return 0;
}

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

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

int main(void)
{
    std::stack<int> n;
    int m;

    while(std::cin >> m)
    {
        if(m == 0)
        {
            std::cout << n.top() << std::endl;
            n.pop();
        }

        else
        {
            n.push(m);
        }
    }

    return 0;
}

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

using namespace std;

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

C++: // includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  vector<int> vec;
  while(cin >> n){
    if(n != 0)vec.pb(n);
    else{
      cout << vec[vec.size() - 1] << endl;
      vec.pop_back();
    }
  }
	return 0;
}

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

stack<int> st;

int main() {
	
	int m, tmp;
	
		
		for(;;)  {
			cin >> m;
			if(m > 0)  {
				st.push(m);
			}
			else if(m == 0)  {
				cout << st.top() << endl;
				st.pop();
				if( st.empty())
				return 0; 
			}
		}	
	return 0;
}

C++: #include <stdio.h>

int main() {
	int a,i,k,m;
	int data[15] = {0};
	int output[15] = {0};
	for (i = 0; i < 15; i++) {
		scanf("%d", &a);
		if (a != 0) {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					data[k] = a;
					break;
				}
			}
		}
		else {
			for (k = 0; k < 15; k++) {
				if (data[k] == 0) {
					for (m = 0; m < 15; m++) {
						if (output[m] == 0) {
							output[m] = data[k - 1];
							break;
						}
					}
					data[k - 1] = 0;
					break;
				}
			}
		}
		if (data[0] == 0) {
			break;
		}
	}
	for (i = 0; i < 15; i++) {
		if (output[i] != 0) {
			printf("%d\n", output[i]);
		}
	}
	return 0;
}

C++: #include <stdio.h>

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

C++: #include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <iomanip>

using namespace std;


int main(void)
{
	int a[100], g = 0,co = 0;

	while (cin >> g)
	{
		if (g != 0)
		{
			co++;
			a[co] = g;
		}
		else
		{
			cout << a[co] << endl;
			a[co] = 0;
			co--;
		}
	}
	return 0;
}

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

using namespace std;

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

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

int main(){
	int a;
	std::stack<int> stack;

	while(std::cin >> a){
		if(a > 0){
			stack.push(a);		//push
		} else{
			std::cout << stack.top() << std::endl;	//表示
			stack.pop();		//pop
		}
	}

	return 0;
}

C++: #include<stdio.h>
#include<stack>

int main(){
	int i=0;
	std::stack<int> train;
	scanf("%d",&i);
	train.push(i);
	while(1){
		scanf("%d",&i);
		if(i==0){
			printf("%d\n",train.top());
			train.pop();
		}else{
			printf("%d\n",train.top());
			train.pop();
			train.push(i);
		}
	}
	return 0;
}