Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	n, err := strconv.Atoi(nextString())
	return n, err
}

func main() {
	scanner.Split(bufio.ScanWords)

	stack := []int{}
	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		if n == 0 { // pop
			fmt.Println(stack[len(stack)-1])
			stack = stack[0:(len(stack) - 1)]
		} else { // push
			stack = append(stack, n)
		}
	}
}

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

int main()
{
	stack<int> s;
	deque<int> ans;
	int n;

	while (cin >> n)
	{
		if (cin.eof()) return 0;
		if (n == 0)
		{
			ans.push_front(s.top());
			s.pop();
			if (s.empty()) break;
		}
		else
		{
			s.push(n);
		}
	}

	while (1)
	{
		if (!ans.empty())
		{
			cout << ans.back() << endl;
			ans.pop_back();
		}
		else break;
	}
	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
#include <stack>
using namespace std;

#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

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

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<stack>

using namespace::std;


int main(){

  stack<int> st;
  int val = 0;
  int ans[100] = {};
  int i = 0;
  int j = 0;

  scanf("%d", &val);
  st.push(val);
  while(!st.empty()){
    scanf("%d", &val);
    if(val == 0){
     ans[i] = st.top();
     i++;
     st.pop();
     continue;
    }
    st.push(val);
  }

  for(j = 0; j < i; j++){
    printf("%d\n", ans[j]);
  }


  return 0;
}

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

int main(){
	std::stack<int> switching_rail;
	std::queue<int> out_number;
	int in_number;
	//Input
	while(std::cin >> in_number){
		if(in_number == 0){
			out_number.push(switching_rail.top());
			switching_rail.pop();
		}else{
			switching_rail.push(in_number);
		}
	}
	//Output
	while(!out_number.empty()){
		std::cout << out_number.front() << std::endl;
		out_number.pop();
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
  int car[10],car2[10]={0};
  stack<int> rail;
  int i=0,j=0;
  while(1){
    cin >> car[i];
    if(car[i] != 0){
      rail.push(car[i]);
	}
    else{
      car2[j]=rail.top();
      rail.pop();
      j++;
    }
    if(rail.size() == 0){
      break;
    }
    i++;
  }
  for(i=0;i<j;i++){
    cout << car2[i] << endl;
  }
}

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

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

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
  stack<int> st;
  int d;
  while(cin >> d){
    if(d == 0){
      cout << st.top() << endl;
      st.pop(  );
    }else {
      st.push( d );
    }
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
//#include<algorithm>
//#include<cmath>
using namespace std;
int main() {
	int A[100];
	int i = 0;
	while (cin >> A[i]) {
		if (A[i] == 0) cout << A[--i] << endl;
		else i++;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstdio>

int main(void)
{
  std::vector<int> in, out;

  while (true) {
    int value;
    std::cin >> value;
    if (value == 0) {
      std::vector<int>::iterator it = in.end() - 1;
      out.push_back(*it);
      in.erase(it);
    }
    else {
      in.push_back(value);
    }
    if (in.size() == 0) {
      break;
    }
  }

  for (std::vector<int>::iterator it = out.begin(); it != out.end(); ++it) {
    std::cout << *it << std::endl;
  }

  return 0;
}

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

int main(){
	std::stack<int> rail;
	
	int x;
	while(std::cin >> x){
		//car exit
		if(x == 0){
			std::cout << rail.top() << std::endl;
			rail.pop();
		}
		//car enter
		else{
			rail.push(x);
		}
	}
	
}

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

int main() {
	vector<int>v;
	vector<int>::iterator pv=v.begin();
	int n;
	while (cin>>n) {
		if (n == 0) {
			int x = v.size();
			cout << v[x - 1] << endl;
			v.pop_back();
			continue;
		}
		v.push_back(n);	
	}
	return 0;
}

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

using namespace std;

int main(){
	int input;
	vector<int> stack;
	while(cin >> input){
		if (input != 0){
			stack.push_back(input);
		}else{
			cout << stack.back() << endl;
			stack.pop_back();
		}

	}

}

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

int main(){
  int a[10],u,count=0;
  while(cin >> u ){
    if(u!=0){
      a[count]=u;
      count++;
    }
    else {
      cout << a[count-1]<<endl;
      count--;
    }
  }
}

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

int train[10];

int main(void){
	int input;
	int index = 0;
	while(cin >> input){
		if(input != 0){
			train[index] = input;
			index++;
		}
		else if(input == 0){
			index--;
			printf("%d\n",train[index]);
			train[index] = 0;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
  stack<int> num;
  int x;
	vector<int> ans;

  while (cin >> x) {
    if (x != 0) {
      num.push(x);
    } else {
      ans.push_back(num.top());
      num.pop();
    }
  }

  x = ans.size();
  for (int i = 0; i < x; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

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

int main(){

	int a;
	int i = -1, j = -1;
	std::vector<int> array1;
	std::vector<int> array2;


	while(std::cin >> a){
		if(a != 0){
			array1.push_back(a);
			i++;
		}else{
			array2.push_back(array1[i--]);
			array1.pop_back();
			j++;
		}
	}
	
	while(j != -1){
		std::cout << array2[j--] <<  std::endl;
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int a[10];
	int k;
	for(int i=0;i<10;i++)
		a[i]=0;
	while(cin>>k){
		if(k==0){
			int i=9;
			while(true){
				if(a[i]!=0){
					cout<<a[i]<<endl;
					a[i]=0;
					break;
				}
				i--;
			}
		}
		else{
			int i=0;
			while(true){
				if(a[i]==0){
					a[i]=k;
					break;
				}
				i++;
			}
		}
	}
	return 0;
}

C++: #include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

stack<int> sta;

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


	return 0;
}

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

int main(){
	stack<int> st;
	queue<int> que;
	int train;
	while(cin >> train){
		if(train)
			st.push(train);
		else{
			que.push(st.top());
			st.pop();
		}
	}
	while(!que.empty()){
		cout << que.front() << endl;
		que.pop();
	}
	return 0;
}