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<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;
}

C++: #include<iostream>
using namespace std;
int main(){
  int number,count1,count2,enter[10],leave[10],sum;
  
  count1=0;
  count2=0;
  for(int i=0;i<10;i++){
    cin >> number;
    if(number!=0){
      enter[count1]=number;
      count1++;}
    else if(number==0){
      count1--;
      leave[count2]=enter[count1];
      count2++;}
    if(count1+2<count2)break;
			}
  for(int i=0;i<count2;i++){
    cout << leave[i]<< endl;
  }
 
  return 0;
  }

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

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

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

int main(){
	//Switching queue
	std::deque<int> que;
	int tmp;
	
	while(std::cin >> tmp){
		if(tmp == 0){
			std::cout << que.back() << std::endl;
			que.pop_back();
		}
		else que.push_back(tmp);
	}
		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; i <= 10 ; i++) {;}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; i <= 10 ; i++) {;}
			train[i] = n;
		}
	}
	for (i = 0; i <= 10 ; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}