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>
#include<stack>
using namespace std;
int main(){
  stack<int> chu;
  int i=0;
  int input;
  int hairetu[10];
  cin>>input;
  chu.push(input);
  while(cin>>input){
    if(input!=0){
      chu.push(input);
    }else{
      hairetu[i]=chu.top();
      chu.pop();
      i++;
    }
  }
  for(int j=0;j<=i-1;j++){
    cout<<hairetu[j]<<endl;
  }
  
}

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

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

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

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

using namespace std;

int main() {
	stack<int> line;
	int n;

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

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

using namespace std;

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

C++: #include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	queue<int> leave;
	stack<int> waiting;
	int n;
	while(scanf("%d",&n)==1){
		if(n==0){
			leave.push(waiting.top());
			waiting.pop();
		}else{
			waiting.push(n);
		}
	}
	while(!leave.empty()){
		cout<<leave.front()<<endl;
		leave.pop();
	}
	return 0;
}

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

int n;
stack<int> st;

int main() {
  while (1) {
    if (scanf("%d", &n) != 1) break;
    if (n == 0) {
      printf("%d\n", st.top());
      st.pop();
    } else {
      st.push(n);
    }
  }
}

C++: /*AOJ 0013*/

#include<iostream>
#include<stack>
#include<queue>

using namespace std;

int main(){

	stack<int> data;
	queue<int> ans;

	int tmp;

	cin>>tmp;

	data.push(tmp);

	int flag = 0;
	while(cin>>tmp){

		flag = 0;

		if(tmp == 0){
			ans.push(data.top());
			data.pop();
		}
		else{
			data.push(tmp);
		}

	}
	while(ans.size()!=0){
		cout<<ans.front()<<endl;
		ans.pop();
	}

	return 0;
}

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

using namespace std;

int main(){

  vector<int> V;

  while(1){
    int in;
    cin >> in;
    if(in != 0) V.push_back(in);
    else{
      cout <<  V.back() << endl;
      V.pop_back();
    }
    
    if(V.empty())break;
  }
  return 0;
}

C++: #include <stdio.h>

#define N 20
int main(void){
    int stk[N], sp=0;
    int n;
   
    while (scanf("%d", &n)){
        if (n==0 && sp!=0){
            printf("%d\n", stk[--sp]);
        } else {
            stk[sp++] = n;
        }
    }
    return 0;
}

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

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

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

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

using namespace std;
int main(){
  int op;
  stack<int> intStack;
  while(cin>> op){
    if(op == 0){
      cout << intStack.top() << endl;
      intStack.pop();
    } else {
      intStack.push(op);
    }
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
	int stack[10];
	int n=0;
	int d;
	while(cin>>d){
		if(d!=0){
			stack[n++]=d;
		}else{
			cout<<stack[--n]<<endl;
		}
	}
}

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

using namespace std;

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

    return 0;
}

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

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

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

C++: #include<stdio.h>
const int SIZE=100;
int data[SIZE];
int sp=0;
int size(){
  return sp;
}
int empty(){
  return sp<=0;
}
int top(){
  return data[sp-1];
}
void pop(){
  sp--;
}
void push(int v){
  data[sp]=v;
  sp++;
}
int main(){
  int n;
  while(n!=EOF){
    scanf("%d",&n);
    if(n==0){
      printf("%d\n",top());
      pop();
    }else{
      push(n);
    }
  }
  return 0;
}

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

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

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

int main(){
	int n,count = 0;
	stack<int> get;
	while(1){
		cin >> n;
		if(n==0){
			cout <<  get.top() << endl;
			get.pop();
			count -= 1;
		}
		else{
			get.push(n);
			count += 1;
		}
	}
	return 0;
}

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

int main(){
	std::vector<int> carsQueue;
	int switchingRailroadCarsNumber;
	while (std::cin >> switchingRailroadCarsNumber){
		if (switchingRailroadCarsNumber != 0){
			carsQueue.push_back(switchingRailroadCarsNumber);
		}
		else{
			std::cout << carsQueue.at(carsQueue.size() - 1) << std::endl;
			carsQueue.pop_back();
		}
	}
	return 0;
}

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

int main() {
	ios :: sync_with_stdio(false);
	stack <int> s;
	int n;
	while(cin >> n) {
		if(n == 0) {
			cout << s.top() << '\n';
			s.pop();
		} else
			s.push(n);
	}
	return 0;
}

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

int main(){
	std::deque<int> que;
	int tmp;
	while(std::cin >> tmp){
		if(tmp == 0){
			std::cout << que.back() << std::endl;
			que.pop_back();
		}
		else que.push_back(tmp);
	}
		return 0;
	}

C++: #include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

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

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

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

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

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

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

int main(){
	int n,a=0,b=0;
	while(true){
		cin>>n;
		if(n!=0){
			if(b==0)b=n;
			if(b!=0)a=n;
		}else{
			if(a!=0){
				cout<<a<<endl;
				a=0;
			}else if(a==0&&b!=0){
				cout<<b<<endl;
				b=0;
			}else if(a==0&&b==0){
				return 0;
			}
		}
	}
	return 0;
}