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;

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();
    }
  }
  return 0;
}

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

int main() {
	std::stack<int> stCar;
	std::queue<int> qOut;
	int number;

	while (std::cin >> number) {
		if (number != 0) {
			stCar.push(number);
		} else {
			qOut.push(stCar.top());
			stCar.pop();
		}
	}

	while (!qOut.empty()) {
		std::cout << qOut.front() << '\n';
		qOut.pop();
	}
	return 0;
}

C++: #include <cstdio>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string> 
#include <vector> 
using namespace std;

int main(){
/*??¢??????????????¨40????????????
	string in[100],n;
	int i = 1,stop = 0,si;
	while(stop == 0){
		cin >> n;
		if(n == "#"){stop = 1;}else{in[i] = n;i++;}						
	}
	string ans[i];
	for(int ii = 1;i > ii;ii++){
		ans[ii] = "A";
		si = in[ii].size();
		for(int iii = 0;si > iii;iii++){
			string c = in[ii].substr(iii,1);
			      if(ans[ii] == "A"){
				if(c == "1"){
					ans[ii] = "Y";
				}else if(c == "0"){
					ans[ii] = "X";
				}
			}else if(ans[ii] == "X"){
				if(c == "1"){
					ans[ii] = "Z";
				}else if(c == "0"){
					ans[ii] = "No";
				}
			}else if(ans[ii] == "Y"){
				if(c == "1"){
					ans[ii] = "No";
				}else if(c == "0"){
					ans[ii] = "X";
				}
			}else if(ans[ii] == "Z"){
				if(c == "1"){
					ans[ii] = "B";
				}else if(c == "0"){
					ans[ii] = "W";
				}
			}else if(ans[ii] == "W"){
				if(c == "1"){
					ans[ii] = "Y";
				}else if(c == "0"){
					ans[ii] = "B";
				}
			}else if(ans[ii] == "B"){
				if(c == "1"){
					ans[ii] = "X";
				}else if(c == "0"){
					ans[ii] = "Y";
				}
			}	
			if(iii == si - 1 and ans[ii] == "B"){ans[ii] = "Yes";}
			if(iii == si - 1){
				if(ans[ii] != "Yes"){ans[ii] = "No";}
				cout << ans[ii] << endl;
			}											
		}
	}*/
	/*	int	X,Y[3],P,ANS[2];
		cin >> X >> Y[1] >> Y[2] >> Y[3] >> P;
		ANS[1] = P * X;
		cout << "[AiUEO]" << P << " " << X << endl;
		if(P > Y[2]){
			ANS[2] = Y[1] + ( Y[3] * ( P - Y[2] ) );
		}else{
			ANS[2] = Y[1];
		}
		if(ANS[1] > ANS[2]){
			cout << ANS[2] << endl;
			cout << ANS[1] << endl;
		}else{
			cout << ANS[2] << endl;
		}*/
//
    int num, top;
    int train[1024];
    int i;

    top = 0;

    while (scanf("%d", &num) != EOF){
        if (num == 0){
            printf("%d\n", train[top - 1]);
            train[top - 1] = 0;
            top--;
        }
        else { 
            train[top] = num;
            top++;
        }
    }

}

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

int main(){

  int stack[10] = {};
  int p = 0;

  while(cin >> stack[p]){
    if(stack[p] == 0){
      cout << stack[p-1] << endl;
      p--;
    }
    else{
      p++;
    }
  }
 
  return 0;
}

C++: #define scanf_s scanf
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 100
int main(void)
{
	int w, n, now = 0;
	int list[MAX] = { 0 };
	do{	
		scanf_s("%d", &n);
		if (n != 0) { list[now] = n; ++now; }
		else { --now; printf("%d\n", list[now]); }
	} while (now != 0);
}

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

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



int main(){

	vector <int> num_array;
	int car_num;
	size_t size();
	while (cin >> car_num){
	
		if (car_num != 0){
			num_array.push_back(car_num);
		}
		else if (car_num == 0){
			cout << num_array[num_array.size() - 1] << endl;
			num_array.pop_back();
		
		}
	}

	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(void){
    int car;
    stack <int> s;
    while(cin >> car){
        if(car != 0)
            s.push(car); //要素を挿入する
        else{
            cout << s.top() << endl; //一番上の要素を参照し、その要素を出力する
            s.pop(); //一番上の要素を削除する
        }
    }
}

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

using namespace std;

stack<int> s;
int ac;

int main(void) {
    freopen("i.in", "r", stdin);
    while(~scanf("%d", &ac)) {
        if(ac == 0) {
            cout << s.top() << endl;
            s.pop();
        } else {
            s.push(ac);
        }
    }
    return 0;
}

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

using namespace std;

int main()
{
	stack<int> trains;
	queue<int> aparted;
	int n, c, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &c);
		if (c == 0)
		{
			aparted.push(trains.top());
			trains.pop();
		}
		else
			trains.push(c);
	}
	while (aparted.empty()!=true)
	{
		printf("%d\n", aparted.front());
		aparted.pop();
	}
	return 0;
}

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

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

C++: #include<iostream>
using namespace std;
int main(){
  
  int a[10],b[10],c=0,d=0,num;

  while(1){

    cin >>num;

    if(num >= 1 && num <=10){
      a[c]=num;
      c++;
    }else if(num == 0){
      b[d]=a[c-1];
      c--;
      d++;
    }

    if( c == 0 )break;

  }

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

  return 0;
}

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

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

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

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);
    }
  }
  return 0;
}

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

int main(void){
     int n[100];
     int i=0;
     int d;
     while(cin >> d,!cin.eof()){
	  
	  if(d == 0){
	       cout << n[i-1] << endl;
	       i = i-1;
	  }else{
	       n[i] = d;
	       i = i+1;
	  }
//	  cout << endl;
//	  for(int i=0;i<10;i++){
//	       cout << n[i-1] << endl;
//	  }
//	  cout << endl;
     }

     return 0;
}

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

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