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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>
#include <stack>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int in;
  stack<int> s;

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

  return 0;
}

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

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

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

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
	stack<int> st;
	int n,ans;

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

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    stack<int> stk;
    for(;;){
        int n;
        if(!(cin >> n))
            return 0;

        if(n == 0){
            cout << stk.top() << endl;
            stk.pop();
        }else{
            stk.push(n);
        }
    }
}

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

int main() {
	int in;
	vector <int> a;
	while (cin >> in;) {
		if (in == 0) {
			cout << a.back();
			a.pop_back();
			/*if (a.size() == 0)
				break;
			else*/
				cout << endl;
		}
		else
			a.push_back(in);
	}
	return 0;
}

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

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

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

int main(int argc,char* argv[]){
  std::vector<int> vec(1000);
  
  while(!std::cin.eof()){
    int temp;
    std::cin >> temp;
    if(temp == 0){
      std::cout << vec.back() << std::endl;
      vec.pop_back();
      continue;
    }else{
      vec.push_back(temp);
      continue;
    }
  }

  return 0;
  
}

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

using namespace std;

int number[100];
int car;
int position = 0;

int main(){
	while(cin >> car){
		if(car > 0){
			number[position] = car;
			position++;
		}else{
			position--;
			cout << number[position] << endl;
		}
	}
}

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;
	do {
		cin >> a;
		if (a == 0) {
			cout << train.back() << endl;
			train.pop_back();
		}
		else {
			train.emplace_back(a);
		}
	} while (train.size()!=0); 
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void)
{
    int a[110][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[101] = {0};
    bool judge = true;
    int tempjudge = 0;
    
    while(judge)
    {
        cin >> a[i][0];
        if(a[i][0] == 0)
        {
            a[i][1] = 1;
            RFOR(j,i,-1)
                if(a[j][1] != 1 )
                {
                    answer[l] = a[j][0];
                    a[j][1] = 1;
                    l++;
                    break;
                }
        }
        REP(k,i+1)
        if(a[k][1] != 1){
                judge = true;
                break;
        }
        else
            judge = false;
                
        
        i++;
    }
    REP(m,l)
    cout << answer[m] << endl;

    return 0;
}

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

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

C++: #include <iostream>

using namespace std;
int main(){
  int a[100],k = 0,o;
  while(1){
    cin >> o;
    if(o == 0){
      cout << a[k-1] << endl;
      k--;
    } else {
      a[k++] = o;
   }
    if(k == 0)break;
  }
}

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

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
    stack<int> st;

    int a;

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

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void)
{
    int a[201][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[201] = {0};
    bool judge = true;
    int tempjudge = 0;
    
    while(judge)
    {
        cin >> a[i][0];
        if(a[i][0] == 0)
        {
            a[i][1] = 1;
            RFOR(j,i,-1)
                if(a[j][1] != 1 )
                {
                    answer[l] = a[j][0];
                    a[j][1] = 1;
                    cout << "ouput"<< answer[l] << endl;
                    l++;
                    break;
                }
        }
        REP(k,i+1)
        if(a[k][1] != 1){
                judge = true;
                break;
        }
        else
            judge = false;
                
        
        i++;
    }

    return 0;
}

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

using namespace std;

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

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

int main(){
	vector<int> hoge;
	int n;
	
	while( scanf("%d", &n) != EOF ){
		
		if(n==0){
			printf("%d\n" , hoge.back());
			hoge.pop_back();
		}else{
			hoge.push_back(n);
		}
		if(hoge.size()==0) break;
	}
	
	return 0;
}

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

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