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

using namespace std;

stack<int>s;

int main(){
    
    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<cstdio>
#include<iostream>
using namespace std;

int main()
{
    int train[10]={0},n,count=0,outTrain[10],trainCount=0;
    while(scanf("%d",&n)!=EOF){
        if(n){
            for(int i=count ; i!=0 ; i--){
                train[i]=train[i-1];
            }
            train[0]=n;
            count++;
        }
        else{
            outTrain[trainCount]=train[0];
            for(int i=0 ; i<count ; i++){
                train[i]=train[i+1];
            }
            train[count]=0;
            count--;
            trainCount++;
        }
    }
    for(int i=0 ; i<trainCount ; i++){
        cout << outTrain[i] << '\n';
    }
    return 0;
}

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(scanf("%d",&n)!=EOF){
		if(n!=0){
			data[i]=n;
			i++;
		}else if(n==0){
			cout<<data[i-1]<<endl;
			i--;
		}
	}
}

C++: 
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	vector<int> train;
	int a;
	while (true) {
		cin >> a;
		if (a == 0) {
			cout << train.back() << endl;
			train.pop_back();
		}
		else {
			train.emplace_back(a);
		}
	}
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

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

    return 0;
}

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

using namespace std;

int main(){

  int train;
  stack<int> s;

  cin >> train;

  s.push(train);

  while(!s.empty()){

    cin >> train;

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

  }

}

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

int main(){
    int n;
    int i=0;
    int s=55;
    int num[105];
    while(cin>>n){
        if(n==0){
            while(1){
                if(num[s]!=0){
                    cout<<num[s]<<endl;
                    num[s]=0;
                    s=55;
                    break;
                }
                s--;
            }

        }
        else {
            while(1){
                if(num[i]==0){
                    num[i]=n;
                    i=0;
                    break;
                }
                i++;
            }
        }
                }
    return 0;
    }

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

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

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

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

using namespace std;

int main(){
	vector<int> stack, seq;
	int n;

	while(cin >> n){
		if(cin.eof()){
			break;
		}
		if(n == 0){
			seq.push_back(stack.back());
			stack.pop_back();
		}else{
			stack.push_back(n);
		}
	}
	for(int& n : seq){
		cout << n << endl;
	}
}

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

using namespace std;

int main() {
    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 <stack>
#include <iostream>
#include <vector>
using namespace std;



int main()
{
stack<int> a;
int d;

while(cin>>d){

if(d!=0) {
a.push(d);
}
else {
cout<<a.top()<<endl;
a.pop();
}
}

}

C++: #include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<stack>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

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

  }
}

C++: #include <stdio.h>

#include <string.h>

#include <stack>

#include <iostream>


using namespace std;

int main(){
    
    int input;
    stack<int> train;
    while (scanf("%d",&input)!=EOF) {
//        scanf("%d",&input);
        if (input!=0)train.push(input);
        else {
            printf("%d",train.top());
            train.pop();
        }
    }
}
    //        if(strcmp(c,pu) == 0){
    //
    //            scanf("%s",&color);
    //
    //            st.push(color);
    //
    //        }
    //
    //        if(strcmp(c,po) == 0){
    //
    //            cout<<st.top()<<endl;
    //
    //            st.pop();
    //
    //        }
    //
    //        if(strcmp(c,qu) == 0){
    //
    //            return 0;
    //
    //        }
    //
    //    }
    
    //}

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

int main(){
	std::stack<int> switching_rail;
	int car_number;
	
	while(std::cin >> car_number){
		if(car_number == 0){
			std::cout << switching_rail.top();
			switching_rail.pop();
		}
		switching_rail.push(car_number);
	}
	
	return 0;
}

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

int main(void)
{
	std::vector<int> incar;

	int n;

	while(std::cin >> n)
	{
		size_t isize=incar.size(); 
		if(n==0)
		{
			//outcar.push_back(incar[isize-1]);
			std::cout << incar[isize-1] << '\n';

			incar.pop_back();
		}
		else
		{
			incar.push_back(n);
		}
	}
}