Go: package main

import "fmt"

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

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

int main()
{
	int train[10000]={},i=0;
	while(1){
		cin>>train[i];
		if(train[i]==0){
			i--;
			cout<<train[i]<<endl;
		}else{
			i++;
		}
	}
}

C++: #include <iostream>
#include<iomanip>
#include <vector>
#include <algorithm>
#include<math.h>
using namespace std;

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

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

  return (0);
}

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

using namespace std;

int main(int argc, char const *argv[]){
    int input; 
    stack<int> train_stack;
    vector<int> order;

    cin>>input;
    train_stack.push(input);
    while (!train_stack.empty()){
        cin>>input;
        if (input==0){
            order.push_back(train_stack.top());
            train_stack.pop();
        }
        else{
            train_stack.push(input);
        }
    }

    for (const auto& tarin_num : order){
        cout<<tarin_num<<endl;
    }
    
    return 0;
}

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

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

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

using namespace std;

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

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

int main(){
    u_int a, end = 0;
    std :: vector<int> v = {};
    while(std :: cin >> a){
        if(a == 0){
            std :: cout << v.at(end-1) << std :: endl;
            v.pop_back();
            end--;
        } else{
            v.push_back(a);
            end++;
        }
    }
}

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

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

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

int main(void){
	std::stack<int> s;
	do{
		int in;
		std::cin >> in;
		if(!in){
			std::cout << s.top() << std::endl;
			s.pop();
		}else{
			s.push(in);
		}
	}while(!s.empty());
	return 0;
}

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

using namespace std;

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

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

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

using namespace std;

int main(){
	stack<int> st;
	int car;
	cin >> car;
	st.push(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 n,oki[1111],ok,ans[11111],an;
	ok = 0;
	an = 0;
	while(cin >> n) {
		if (n == 0) {
			an = an + 1;
			ans[an] = oki[ok];
			ok = ok - 1;
		}
		else {
			ok = ok + 1;
			oki[ok] = n;
		}
	}
	for (int i = 1; i <= an; i++) {
		cout << ans[i] << endl;
	}
}

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

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

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

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

C++: #include<iostream>
using namespace std;
int main(){
  int number,count1,count2,enter[11],leave[11],sum;
  sum=0;
  count1=0;
  count2=0;
  while(1){
    cin >> number;
    if(number!=0){sum++;
      enter[count1]=number;
      count1++;}
    else if(number==0){
      count1--;
      leave[count2]=enter[count1];
      count2++;}
    if(sum-1<count2)break;
			}
  for(int i=0;i<count2;i++){
    cout << leave[i]<< endl;
  }
 
  return 0;
  }

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

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

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

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	vector<int> v1;
	int a;
	while(cin>>a){
		if(a==0){
			a=v1.back();
			v1.pop_back();
			cout<<a<<endl;
		}else{
			v1.push_back(a);
		}
	}
	return 0;
}

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

int main(void){
	std::vector<int> trainID; //list of inputted trainID
	int tmp;

	std::cin >> tmp; //input trainID
	trainID.push_back(tmp); //add trainID

	while(std::cin >> tmp){  //input trainID or 0
		if(tmp == 0){
			std::cout << trainID.back() << std::endl; //output last trainID
			trainID.pop_back(); //delete outputted trainID
		}else{
			trainID.push_back(tmp); //add trainID
		}
	}

	return 0;
}

C++: #include<stdio.h>
int main(){
  int sp=0,data[9],n,i;
  for(i=0;i<100;i++){
    scanf("%d",&n);
    if(n==0){
      printf("%d\n",data[sp]);
      sp--;
    }else{
      sp++;
      data[sp]=n;
    }
  }
}

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

int main(){
    
	using namespace std;
	
	int a;
	int i,j;
	stack<int> s;
	
	while(scanf("%d",&a)!=-1){
		if(a==0){
			
			cout<<s.top()<<endl;
			s.pop();
		}
		else{
			
			s.push(a);
		}
	
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <stdio.h>

#define MAX 1000000

using namespace std;

int main()
{
	vector<int> input;
	int n;

	while(cin>>n){
		if(n==0){
			cout<<input[input.size()-1]<<endl;
			input.pop_back();
		}
		else input.push_back(n);
	}

	return 0;
}

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

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