Go: package main

import (
        "fmt"
)

func main() {
        var stk [101]int
        var c int
        pvt := 0
        for {
                _, err := fmt.Scanf("%d", &c)
                if err != nil {
                        break
                }
                if c > 0 {
                        stk[pvt] = c
                        pvt++
                } else {
                        pvt--
                        fmt.Printf("%d\n", stk[pvt])
                }
        }
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>


using namespace std;

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

	return 0;
}

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

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){
   printf("%d\n", top());
   pop();
  }
 }
 return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<stack>
int main(){
    using namespace std;
    stack <int>S;
    int a;
    while(~scanf("%d",&a)){
        if(a==0){
            printf("%d\n",S.top());
            S.pop();
        }
        else{
            S.push(a);
        }
    }
}

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

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

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

using namespace std;

int main()
{
	stack<int> hako;
	int temp[100];
	int t, i = 0;
	
	cin >> t;
	
	hako.push(t);
	while(hako.size() != 0){
		cin >> t;
		if(t == 0){
			temp[i] = hako.top();
			hako.pop();
			i++;
		}
		else{
			hako.push(t);
		}
	}
	
	for(int j = 0; j < i; j++){
		cout << temp[j] << endl;
	}
	
}

C++: #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <queue>
#include <vector>

using namespace std;

int main() {
  int i = 0, x, s[10];
  while (scanf("%d", &x) == 1)
    if (!x)
      printf("%d\n", s[--i]);
    else
      s[i++] = x;
  return 0;
}

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

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

    while(std::cin >> number){
        if(number != 0)
            st.push(number);
        else{
            std::cout << st.top() << std::endl;
            st.pop();
        }
    }
    
    return 0;
}

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

using namespace std;

int main(){
	stack<int> st;
	int car;
	cin >> car;
	while( !st.empty() ){
		int inout;
		cin >> inout;
		if(inout == 0){
			cout << st.top() << endl;
			st.pop();
		}else{
			st.push(inout);
		}
	}
	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++) {}
			junban[a] = train[i - 1];
			train[i - 1] = 0;
			a++;
		}
		else {
			for (i = 0; train[i] != 0; i++) {}
			train[i] = n;
		}
	}
	for (i = 0; junban[i] > 0; i++) {
		cout << junban[i] << endl;
	}
	return 0;
}

C++: #include<iostream>int main(){int a,c=0,s[12];while(std::cin>>a){if(a!=0)s[c++]=a;else std::cout<<s[--c]<<"\n";}return 0;}

C++:  /*
This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.

We can simulate the movement (comings and goings) of the cars as follow:

An entry of a car is represented by its number.
An exit of a car is represented by 0
For example, a sequence

1 6 0 8 10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.

Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.
 */
 
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	vector<int> cars, ans;
	int temp, i=0, m;
	while (cin >> temp) {
		if (temp != 0) {
			cars[i] = temp;
			i++;
		} else {
			ans.push_back(cars.at(i-1));
			i--;
		}
	}
	for (int j=0; j<ans.size(); j++)
		cout << ans[j] << endl;
	return 0;
}

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

using namespace std;
int main()
{
	stack<int> st;
	int i, n;
	
	while(cin >> n)
	{
		if(n != 0)
		{
			st.push(n);
		}
		else
		{
			i = st.top();
			cout << i << endl;
			st.pop();
		}
	}
	
	return 0;
}

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

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

C++: #include<iostream>
#include<vector>
int main(){
	std::vector<int> car,ans;
	int a;
	//int h=0;
	bool f=false;
	//std::vector<int>::iterator it=car.begin();
	while(std::cin>>a){
		if(a!=0&&!f){
			car.push_back(a);
			f=true;
		}else if(a!=0){
			//h++;
			//++it;
			car.push_back(a);
		}else{
			//ans.push_back(car[h]);
			//ans.push_back(n);
			ans.push_back(car.back());
			//it--;
			car.pop_back();
			//h--;
		}
	}
	for(int i=0;i<ans.size();i++){
		std::cout<<ans[i]<<std::endl;
	}

	return 0;
}

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

using namespace std;

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

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

#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)

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

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

	return 0;
}

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

using namespace std;

int main(){
  int n;
  vector<int> Stop, Free;

  while(cin >> n){
    if(n == 0){
      n = Stop[Stop.size()-1];
      Stop.pop_back();
      Free.push_back(n);
    }else{
      Stop.push_back(n);
    }
  }

  for(vector<int>::size_type i=0; i != Free.size(); ++i){
    cout << Free[i] << endl;
  }

  return 0;
}

C++: #include<stdio.h>
int main(void)
{
    int train[10]={0},n,count=0,outTrain[10],trainCount=0;
    while(scanf("%d",&n)!=EOF){
        if(n){
            for(int i=count ; i!=0 ; i--){
                train[i]=train[i-1];
            }
            train[0]=n;
            count++;
        }
        else{
            outTrain[trainCount]=train[0];
            for(int i=0 ; i<count ; i++){
                train[i]=train[i+1];
            }
            train[count]=0;
            count--;
            trainCount++;
        }
    }
    for(int i=0 ; i<trainCount ; i++){
        printf("%d\n",outTrain[i]);
    }
    return 0;
}

C++: #include <stdio.h>

int train(int array[], int a)
{
	int i;
	for(i=0; i<10; i++)
	{
		if(array[i]==0)
		{
			if(a)
			{
				array[i]=a;
				return 0;
			}
			
			if(i>0 && a==0)
			{
				printf("%d\n", array[i-1]);
				array[i-1]=0;
				return 0;
			}
		}
	}
}
	

int main (void)
{
	int a, trains[10], i;
	
	for(i=0; i<10; i++)
	{
		trains[i]=0;
	}
	
	while(scanf("%d", &a)!=EOF)
	{
		train(trains, a);
	}
	
	return 0;
}