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<stdio.h>
int main(){
int a[100];
int j;
for(int i=0;;i++){
scanf("%d",&a[i]);
if(a[i]==0){
j=i;
while(){
if(j-1!=0){
printf("%d",a[j-1]);
break;
}
j--;
}
a[j-1]=0;
if(j-1==0){
break;
}
}
}

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

using namespace std;

const int N = 1000000;

int stack[N], top = 1;

int main() {
	int n;
	top = -1;
	scanf ("%d", &stack[++top]);
	while (top >= 0) {
		scanf ("%d", &n);
		if (n) stack[++top] = n;
		else printf ("%d\n", stack[top--]);
	}
	return 0;
}

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

using namespace std;

int main(){
	stack<int> st;

	while( 1 ){
		int inout;
		cin >> inout;
		if(cin.eof()) break;

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

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

using namespace std;

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

int main()
{
	solve();
	return(0);
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(){
  int train[10];
  int by[10];
  int a,i=0,j=0,c=0;
  while(scanf("%d",&a)){
    if(a==0){
      i--;
      by[j]=train[i];
      j++;
      c--;
      if(c==0)break;
    }
    else{
      train[i]=a;
      i++;
      c++;
  }
  }
  for(int i=0;i<j;i++){
    cout<<by[i]<<endl;
  }
}

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 && sp>0){
      sp--;
      printf("%d\n",data[sp]);
    }else{
      data[sp]=n;
      sp++;
    }
    if(sp==0)break;
  }
  return 0;
}

C++: //include---------------------------------------------------------------------------
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cctype>
#include<vector>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<algorithm>


//using namespace-------------------------------------------------------------------
using namespace std;

//define,const----------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < n; i++){
const int INF = 1 << 25;

//global----------------------------------------------------------------------------
stack<int> cars;
int numbar;

//function--------------------------------------------------------------------------
int main(){
	while(scanf("%d", &numbar) != EOF){
		if(numbar == 0){
			printf("%d\n", cars.top());
			cars.pop();
			continue;
		}
		cars.push(numbar);
	}
	return 0;
}

C++: #include<stdio.h>
int main(){
int a[100];
int j,a=0;
for(int i=0;i<100;i++){
scanf("%d",&a[i]);
if(a[i]==0){
j=i;
while(a=0){
if(j-1!=0){
printf("%d",a[j-1]);
a=1;
}
j--;
}
a=0;
a[j]=0;
if(j-1==0){
i=101;
}
}
}

C++: #include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	stack<int> train;

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

	return 0;
}

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

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

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

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

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
const int inf=(1<<31)-1;

int n;
vi num;

int main(){
	while(cin>>n){
		if(n) num.push_back(n);
		else{
			cout<<num.back()<<endl;
			num.pop_back();
		}
	}
}

C++: #include<stdio.h>

int main(){
  int i = 0, x;
  int data[100];
  scanf("%d", &x);
  while(x != EOF){
    if(x != 0){
      data[i] = x;
      i++;
    }else{
      printf("%d\n", data[i-1]);
      i--;
    }
  }
  return 0;
}

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

stack <int> st;

void enter(int car) {
  st.push(car);
}

void exit() {
  cout << st.top() << endl;
  st.pop();
}

int main() {
  int car;
  while (cin >> car) {
    if (car == 0) {
      exit();
    } else {
      enter(car);
    }
  }
}

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++: #include <iostream>
#include <stack>
using namespace std;

//0013
int main(){
	int x;
	stack<int> s;

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

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    
    int tmp;
    stack<int> s;
    queue<int> q;
    
    while(cin >> tmp) {
        if(tmp == 0) {
            q.push(s.top());
            s.pop();
        } else {
            s.push(tmp);
        }
    }
    
    while(!q.empty()) {
        cout << q.front() << endl;
        q.pop();
    }
    
    return 0;
}

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

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

C++: #include<stdio.h>

int	i	=	0,	result;
int	train[100];
int outtrain[100];

void	push(int	k){
	train[i]	=	k;
	i++;
}

void	pop(int train[]){
	int	a,	check	=	0;
	for(a	=	i	-	1;	a	>=	0;	a--){
		if(train[a]	!=	0){
			result	=	train[a];
			train[a]	=	0;
			check	+=	1;
		}
		if(check	!=	0)break;
	}
}


int	main(){
	int	k,	cnt	=	0;
	outtrain[100]	=	0;
	while(1){
		scanf("%d",	&k);
		push(k);
		if(k	==	0){
			pop(train);
			outtrain[cnt]	=	result;
			cnt++;
			i	-=	2;
		}
		if(i	==	0)break;
	}
	for(k	=	0;	k	<=	cnt;	k++){
		if(outtrain[k]	!=	0)printf("%d\n",	outtrain[k]);
	}
}

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


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

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

using namespace std;

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

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

int main(){
	std::vector<int> line;
	std::vector<int> out;
	int a;

	while(std::cin >> a){
		if(a != 0){
			line.push_back(a);
		}else if(a == 0){
			out.push_back(line.back());
			line.pop_back();
		}
	}

	for(int i=0; i<(int)out.size(); ++i){
		std::cout << out.at(i) << std::endl;
	}
}

C++: #include <iostream>
#include <deque>
using namespace std;
 
int main(int argc, char** argv) {
    deque<int> deq;
    int n;
    while(cin >> n) {
        if(n == 0) {
            cout << deq.back() << endl;
            deq.pop_back();
        }else {
            deq.push_back(n);
        }
    }
    return 0;
}