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++:  /*
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>

using namespace std;

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

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

int main(int argc,char* argv[]){
  std::vector<int> vec;
  
  while(!std::cin.eof()){
    int temp;
    std::cin >> temp;
    if(temp == 0){
      std::cout << vec.back() << std::endl;
      vec.pop_back();
      continue;
    }else{
      vec.push_back(temp);
      continue;
    }
  }

  return 0;
  
}

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

int main()
{
	int n;
	stack<int> car;
	vector<int> out;

	while (cin >> n){
		if (n == 0){
			out.push_back(car.top());
			car.pop();
		}
		else {
			car.push(n);
		}
	}

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

	return (0);
}

C++: #include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

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

  while(scanf("%d", &a)!=EOF)
    {
      if(a==0)
	{
          cout<<n.top()<<endl;
          n.pop();
	}

      else
        n.push(a);
    }
}

C++: #include<iostream>
using namespace std;
int main(){
  int i=0,num,a[10],b[10],x=0;
  
  while(cin>>num){
    int count=0;
    count++;
    if(num==0){
      b[x++]=a[i-1];
      i--;
    }
    else  a[i++]=num;
    if(!i)break;
  }

  for(i=0;i<x;i++)
    cout<<b[i]<<endl;
  return 0;
}

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

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

C++: #include <fstream>
#include <iostream>
#include <stack>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

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

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

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

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

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

C++: #include <bits/stdc++.h>
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);
    }
  }
  return 0;
}

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

int main(){
  list<int> rails;
  int car;

  while(cin >> car){
    if(car == 0){
      cout << *(--rails.end()) << endl;
      rails.pop_back();
    }
    else
      rails.push_back(car);
  }
  
  return 0;
}

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

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

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> inc,ouc;
int cmd;
while(1){
if(!(inc.size())&&ouc.size())break;
cin >> cmd;
if(!cmd)ouc.push_back(inc[inc.size()-1]),inc.pop_back();
else inc.push_back(cmd);
cout << inc.size() << endl;
}
for(int i = 0;i<ouc.size();i++)
cout << ouc[i] << endl;
return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);

    stack<uint> carbarn;
    carbarn.push(0);            // dummy
    uint input;

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

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

int main(void){
  using namespace std;
  
  std::vector <int> train; 
  
  int temp;
  
  while(1){
    cin >> temp;
    if(cin.eof()){break;}


    if(temp!=0){
      train.push_back(temp);
    }

    else if(temp==0)
    {
      int last=train.back();
      train.pop_back();
      cout << last << endl;
    }

  }

  return 0;
}