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

C++: #include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#include<stack>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)

using namespace std;
typedef long long ll;


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

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

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

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

using namespace std;

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

  while( cin >> in )
  {
     if (!in)
     {
        cout << s.top() << endl;
        s.pop();
     }
     else
     {
        s.push(in);
     }
  }
  return 0;
}

C++: #include<stdio.h>
int main(){
	int a,b,c,d,train[100],memory[100];
	b=0;
	c=0;
	
	int g;
	int cont = 0;
	
	for(a=0;a<100;a++){
		scanf("%d",&g);
		
		if(g != 0){
			train[cont] = g;
			cont++;
		}
		else{
			printf("%d\n",train[cont-1]);
			cont--;
		}
		
		if(cont == 0){
			break;
		}
		/*
		if(train[a]==0){
			c++;
		}else{
			b++;
		}
		if(b==c){
		break;
		}
		*/
	}
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	vi input;
	int n;
	while(cin >> n) {
		input.push_back(n);
	}

	stack<int> S;
	REP(i, input.size()) {
		if(input[i]) {
			S.push(input[i]);
		} else {
			cout << S.top() << endl;
			S.pop();
		}
	}

	return 0;
}

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

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

}

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,k;
  while(scanf("%d",&n)!=EOF){
    if(n==0){
      printf("%d\n",top());
      pop();
    }else{
      push(n);
    }
  }
  return 0;
}

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

int main()
{
	stack<int> car;
	vector<int> outlist;

	while( !car.empty() || outlist.empty() )
	{
		int carnum;
		cin >> carnum;
		if(carnum)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}

	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

C++: // 2011/06/04 Tazoe

#include <iostream>
#include <stack>
using namespace std;

int main()
{
	stack<int> st;

	while(true){
		int n;
		cin >> n;
		if(cin.eof())
			break;

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

	return 0;
}

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

int main(void){
	double n;
	stack <double> buf;

	while (true){
		cin>>n;
		if (cin.eof()) break;

		if (n!=0) buf.push(n);
		else{
			cout<<buf.top();
			buf.pop();
		}
	}
    return 0;
}

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

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

C++: #include<iostream>

using namespace std;

int main() {
	int train[11] = { 0 }, junban[11] = { 0 }, a = 0, n, i;	
	while (cin >> n) {
		if (n == 0) {
			for (i = 0; i <= 10 && train[i] != 0; i++) {;}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; i <= 10 && train[i] != 0; i++) {;}
			train[i] = n;
		}
	}
	for (i = 0; i <= 10 && junban[i] > 0; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<math.h>

using namespace std;
#define C(_Str) cout << _Str << endl
typedef long long int lli;

int main()
{
	int Num,i=0,j=0,k=0;
	vector<int> Car(100);
	vector<int> Out(100);
	while (cin >> Num) {
		
		if (Num != 0) {
			Car[i] = Num;
			i++;
		}
		else {
			i--;
			Out[j] = Car[i];
			j++;
		}
	}
	while (Out[k]) { 
		cout << Out[k] << endl;
		k++;
	}
	return 0;
}

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

using namespace std;

stack<int>s;
int cou[100];
int c=0;

int main(){
   
    do{
        int n;
        cin>>n;
        if(n){
            s.push(n);
        }else{
            //cout<<s.top()<<endl;
            cou[c]=s.top();
            s.pop();
            c++;
        }
    }while(s.size());
    
    for(int i=0;i<c;i++){
        cout<<cou[i]<<endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int in;
  queue<int>out;
  while(cin>>in){
    if(in)out.push(in);
    else {
      cout<<out.front()<<endl;
      out.pop();
    }
  }


}

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

int main(){

	int in;
	stack<int> st;

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

}

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

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

int main(){
stack<int>a;
int b;
scanf("%d",&b);
a.push(b);
while(cin>>b){
	if(b)a.push(b);
	else {printf("%d\n",a.top());a.pop();}
}
}