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 <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B)          for(int I=A; I<B; I++)
#define LL                  long long
#define PII                 pair<int,int>
#define MOD                 1000000007
#define MAX                 1000005
#define READ(A)             freopen(A,"r",stdin)

int main() {
    //READ("input.txt");
    stack<int>S;
    int N;

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

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

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

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

C++: #include<stdio.h>
int main(){
  int sp=0,data[10],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++;
    }
  }
  return 0;
}

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

int main()
{
        int train;
        stack<int> out;
        while(cin >> train)
        {
                if(train != 0){
                        out.push(train);
                }
                else{
                        cout << out.top() << " ";
                        out.pop();
                }
        }
        return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
	int num, tmp[10] = {0}, num_out[100] = {0};
	int cnt_1 = 9, cnt_2 = 0;
	
	while (scanf("%d", &num) != EOF){
		if (num == 0){
			num_out[cnt_2] = tmp[cnt_1 + 1];
			printf("num_out[%d]=%d\n", cnt_2, num_out[cnt_2]);
			cnt_2++;
			cnt_1++;
		}
		else {
			tmp[cnt_1] = num;
			printf("tmp[%d]=%d\n", cnt_1, tmp[cnt_1]);
			cnt_1--;
		}
	}
	
	for (int i = 0; i < 100; i++){
		if (num_out[i] != 0){
			printf("%d\n", num_out[i]);
		}
	}
	
	return (0);
}

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

int main() {
	int temp; vector<int> vec(0);
	while (cin >> temp) {
		if (temp == 0) {
			cout << vec[vec.size() - 1] << endl;
			vec.pop_back();
		}
		else vec.push_back(temp);
	}
	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 <vector>
#include <stack>
#include <math.h>
#include <string>
#include <cmath>
#include <iomanip>

int main();


int main(){
	std::stack<int> input;		//入力される数（電車番号）を格納する
	int dummy = 0;				//ダミーナンバー

	while (std::cin >> dummy){
		if (dummy == 0){
			input.pop();
		}
		else{
			input.push(dummy);
		}
	}

	while (!input.empty()){
		std::cout << input.top() << std::endl;
		input.pop();
	}

	//while (1);
	return 0;
}

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

using namespace std;

int main(){
    stack<int> in;
    for(int n; cin >> n; )
        if(n != 0) in.push(n);
        else cout << in.top() << endl, in.pop();

    return 0;
}

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

int main() {
	int rail[10]={0};
	int n,i=0;
	while(cin>>n){
		if(n==0){
			cout<<rail[i-1]<<endl;
			i--;
			continue;
		}
		rail[i]=n;
		i++;
	}
	return 0;
}

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

using namespace std;

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

	while (~scanf("%d", &in)){
		if (in) st.push(in);
		else {
			printf("%d\n", st.top());
			st.pop();
		}
	}

	return (0);
}

C++: #include<iostream>
using namespace std;
int main(){
int a[]={0,0,0,0,0,0,0,0,0,0};
int b;
while(cin>>b){
if(b==0){
cout<<a[0];
for(int i=0;i<9;i++){
a[i]=a[i+1];}}
else{
for(int i=0;i<8;i++){
a[9-i]=a[8-i]}
a[0]=b;}}

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(j1!=0){
printf("%d",a[j1]);
break;
}
j--;
}
}
}

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

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num == 0 && point > 0) pop();
		else push(num);
	}

    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int car[105];
    int num;
    int i=0;
    while(1){
        cin>>num;
        if(num!=0){
            car[i]=num;
            i++;}
        else{
            i--;
            cout<<car[i]<<endl;
            car[i]=0;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()

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

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

using namespace std;

int main(void) {
  int num;
  stack<int> stk;

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

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

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

int main(){
	int n;
	stack<int> stk;
	queue<int> que;
	while(1){
		cin>>n;
		if(n==0){
			que.push(stk.top());
			stk.pop();
		}else{
			stk.push(n);
		}
		if(stk.empty())break;
	}
	while(!que.empty()){
		cout<<que.front()<<endl;
		que.pop();
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

using namespace std;

stack<int> st;
queue<int> qu;
int a;

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