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 <stdio.h>

int train[10];
int sp = 0;

int empty() {
  return sp <= 0;
}

int size() {
  return sp;
}

int top() {
  return train[sp-1];
}

void pop() {
  sp--;
}

void push(int v) {
  train[sp] = v;
  sp++;
}

int main(){
  int out[10];
  int num, i = 0;
  while(1){
    scanf("%d", &num);
    if(num == 0){
      out[i] = top();
      i++;
      pop();
    }else if(1 <= num && num <= 10){
      push(num);
    }
    if(size() == 0) break;
  }
  for(i = 0, i < 10, i++){
    printf("%d\n", out[i]);
  }
  return 0;
}

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

int main(){
	int tmp,i = 0,j,k = 0,f[11];
	vector<int> ans;

	while(cin>>tmp){
		if(tmp == 0){
			ans.push_back(f[i-1]);
			f[i-1] = '\0';
			i--;
			k++;
		}
		else{
		f[i] = tmp;
		i++;
		}
	}
	for(j = 0;j < k;j++){
		cout<<ans[j]<<endl;
	}
	return 0;
}

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

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

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

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

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

//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<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; train[i] != 0; i++) {i+1;}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; train[i] != 0; i++) {i+1;}
			train[i] = n;
		}
	}
	for (i = 0; junban[i] > 0; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int main() {

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

  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();
		}
	}
	
	cout << '\n';
	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

C++: #include <cstdio>

using namespace std;

int main()
{
	int in[10];
	int i = 0;

	while (scanf("%d", &in[i])){
		if (in[i] == 0){
			i--;
			printf("%d\n", in[i]);
		}
		else {
			i++;
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	int now=-1;
	int n[10]={0};
	int in;
		while(cin>>in){
		if(in==0){
			cout<<n[now];
			now--;
			if(now==-1)return 0;
		}
		else{
			n[now+1]=in;
			now++;
		}
	}
}

C++: #include　<iostream>

int stack[100];
int point=0;

void push(int p){
	stack[point]=0;
	++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) pop();
		else push(num);
	}

    return 0;
}

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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

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

C++: #include<iostream>

using namespace std;

int main(){

int aaa[200];
int ii=0;

while(cin>>aaa[ii]){
ii++;
}

for(int i=0;i<ii;i++){
if(aaa[i]==0){
for(int j=i-1;;j--){
if(aaa[j]!=0){
cout<<aaa[j]<<endl;
aaa[j]=0;
break;
}
}
}
}


}

C++: #include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp= 0;

int size(){
 return sp;
}

int top(){ return data[sp-1];
}
void pop(){
 sp--;
}

void push(int v){
 data[sp] = v;
 sp++;
}

int main(){
 int v;
 while(scanf("%d", &v) != EOF){
  if(v != 0){
    push(v);
  }
  if(v == 0){
   pop();
  }
  top();
  printf("%d\n", top());
 }
}

C++:     #include <iostream>
    using namespace std;
     
    int a[11], b, t;
     
    int main() {
      cin>>a[0];
      t=1;
      c=0;
     
      while(cin>>b) {
        if(b>0) {
          a[t]=b;
          t++;
        }else {
          cout<<a[t-1]<<endl;
          t--;
        }
      }
      
      return 0;
    }

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

struct stack{
	int element;
	struct stack *next;
};
int top(struct stack *s){
	return s->element;
}
struct stack* pop(struct stack *s){
	struct stack *p, *q;
	q = s;
	p = s->next;
	free(q);
	s = p;
	return s;
}
struct stack* push(struct stack *s, int x){
	struct stack *p, *q;
	q = s;
	p = (struct stack*)malloc(sizeof(struct stack));
	p->element = x;
	p->next = q;
	s = p;
	return s;
}

int main(){
	struct stack *S=NULL;
	int num;
	while (1){
		cin>>num;
		if (num==0){
			cout<<top(S)<<endl;
			S = pop(S);
		} else{
			S=push(S, num);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main() {
	int a;
	vector<int> s;
	while (cin >> a) {
		if (a != 0) {
			s.push_back(a);
		}
		else if (a == 0) {
			cout << s[s.size() - 1] << endl;
			s.pop_back();
		}
	}
	return 0;
}

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

using namespace std;

int main(){

  int train;
  stack<int> s;

  cin >> train;

  s.push(train);

  while(!s.empty()){

    cin >> train;

    if(train) s.push(train);
    else {
      cout << s.top() << endl;
      s.pop();
    }

  }

}