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 <stack>
#include <vector>

using namespace std;

int main() {
	int data[10];
	stack<int> line;
	vector<int> top;
	int i = 0;

	while (cin >> data[i]) {
		++i;
	}

	for (auto i : data) {
		if (i == 0) {
			top.push_back(line.top());
			line.pop();
		}
		else {
			line.push(i);
		}
	}

	for (auto t : top) {
		cout << t << endl;
	}

	return 0;
}

C++: #include <iostream>

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

C++: #include<iostream>
#include<stack>
#include<vector>
using namespace std;
stack<int>S; int a; vector<int>t;
int main() {
	cin >> a;
	S.push(a);
	while (cin >> a) {
		if (a == 0) {
			t.push_back(S.top());
			S.pop();
		}
		else {
			S.push(a);
		}
	}
	for (int i = 0; i < t.size(); i++) {
		cout << t[i] << endl;
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

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

int main(){
	int k;
	stack<int> q;

	cin >> k;
	q.push(k);

	while (1){
		cin >> k;
		if (k != 0)
			q.push(k);
		else{
			printf("%d\n", q.top());
			q.pop();
		}
		if (q.empty())
			break;
	}
}

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) pop();
		else push(num);
	}

    return 0;
}

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

int main(){
	std::stack<int> st;

	//car's number
	int num = 0;

    //Until the end of input
	while(std::cin >> num){
        //if num = 0, output and delete
		if(num == 0){
			std::cout << st.top() << std::endl;
			st.pop();
        //if num != 0, input    
		} else {
			st.push(num);
		}
	}
}

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

int car_n;
std::stack<int> st;

bool get_input()
{
	return (std::cin >> car_n);
}

int main()
{
	while (get_input()) {
		if (car_n == 0) {
			std::cout << st.top() << std::endl;
			st.pop();
		} else {
			st.push(car_n);
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <stack>

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

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){
	stack<int> stk;
	int a;
	
	while(cin>>a){
		if(a){
			stk.push(a);
		}else{
			cout<<stk.top()<<endl;
			stk.pop();
		}
	}

	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(5);
	solve();

	return 0;
}

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

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

	}
    return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int a;
  stack<int> st;
  while (cin >> a) {
    if (a == 0) {
      cout << st.top() << endl;
      st.pop();
    } else {
      st.emplace(a);
    }
  }

  return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  stack<int> chu;
  int i=0;
  int input;
  int hairetu[111];
  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>
#include <queue>

int main(){
	std::stack<int> in;
	std::queue<int> out;
	int num;
	
	//input
	do{
		std::cin >> num;
		if(num == 0){
			out.push(in.top());
			in.pop();
		}else
			in.push(num);
	}while(!in.empty());
	
	//output
	while(!out.empty()){
		std::cout << out.front() << std::endl;
		out.pop();
	}
	
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-6;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    int n;
    stack<int> q;
    while(cin>>n){
        if(n==0){
            cout<<q.top()<<endl;
            q.pop();
        }else{
            q.push(n);
        }
    }
}

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

int main(void)
{
	stack<int> car;
	int n;

	while(cin >> n) {
		if(n)
			car.push(n);
		else {
			cout << car.top() << endl;
			car.pop();
		}
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
class Stack_10{
private:
	int num;
	int x[10];
public:
	Stack_10(){num=0;};
	void push(int i){
		if(num<10){			
			x[num]=i;
			num++;
		}
	};
	int pop(){
		if(num>0){
			num--;
			return x[num];
		}
		else return -1;
	
	};
};
	
int main(int argc, char *argv[]){
	int car;
	Stack_10 stack;
	while(cin>>car){
	if(car>0) stack.push(car);
	else cout<<stack.pop()<<endl;
}

	return 0;
}

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


int main(){
    using namespace std;

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

C++: //#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int car[100];
  int n,i=0;
  while(cin>>n){
    if(n==0){
      cout<<car[i]<<endl; i--;
    }
    else {
      i++; car[i]=n;
    }
  }
  return 0;
}

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


int main(){

  int train[10] , num[10];

 for( int i = 0; i < 10; i++ ){
    train[i] = 0;
    num[i] = 0;
 }

  for( int i = 0; i < 10; i++ ){

    cin >> train[i];

    if( train[i] == 0 ){
      for( int j = i; j >= 0; j-- ){
	if( train[j] != 0 ){
	num[i] = train[j];
	train[j] = 0;
	break;
	}
      }
    }
  }
  

  for( int k = 0; k < 10; k++ ){
    if( num[k] != 0 ) cout << num[k] << endl; 

  }


  return 0;
}

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

int main(){
	
	int no;

	stack<int> st;
	
	do{
		cin >> no;
		
		if(no == 0){
			cout << st.top() << endl;
		    st.pop();
		}else{
			st.push(no);
		}
		
	}while(st.empty() == false);
	
	return 0;
}