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<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(cin >> car[i]){
    if(car[i] != 0){
      rail.push(car[i]);
	}
    else{
      car2[j]=rail.top();
      rail.pop();
      j++;
    }
    i++;
  }
  for(i=0;i<j;i++){
    cout << car2[i] << endl;
  }
}

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

int main(){

  vector<int> vc;
  int n;

  while(cin >> n){
    if(n != 0){
    	vc.push_back(n);
    }
    else{
      cout << vc.back() << endl;
    	vc.pop_back();
    }
  }
  
  return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cstring>

using namespace std;

int main(){
	stack<int> garage;
	vector<int> out;
	int enter;
	while(cin >> enter){
		if(enter == 0){
			out.push_back(garage.top());
			garage.pop();
		}
		else{
			garage.push(enter);
		}
	}

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

	return 0;
}

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

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> a;
  queue<int> ans;
  int box;
  while(1){
    cin >> box;
    if(box){
      a.push(box);
    }else{
      ans.push(a.top());
      a.pop();
    }
    if(a.empty())break;
  }
  while(1){
    cout << ans.front() << endl;
    ans.pop();
    if(ans.empty())break;
  }
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main( void )
{
  int d;
  stack<int> s;
  while( 1 ){
    cin >> d;
    if( cin.eof() ) break;
    if( d ) s.push( d );
    else { cout << s.top() << endl; s.pop(); }
  }
  return 0;
}

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

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

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

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

int main(void){
	int n;
	stack<int> st;
	while(cin >> n){
		if(n==0){
			cout << st.top() << "\n";
			st.pop();
		}else st.push(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 <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	vector<int> cars(100000), ans;
	int temp, i=0, m;
	while (scanf("%d\n", &temp)) {
		if (temp != 0) {
			cars[i] = temp;
			i++;
		} else {
			ans.push_back(cars[i-1]);
			i--;
		}
	}
	for (int j=0; j<ans.size(); j++)
		cout << ans[j] << endl;
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>

using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

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

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

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

int main(){
    std::vector<int> in_train;
    std::vector<int> out_train;
    
    int a; //for input

    while(std::cin >> a){
        if(a == -1){
	    break;
	}else if(a > 0){
	    in_train.push_back(a);
	}else if(a == 0){
	    int e = in_train.back();
	    //std::cout << e << std::endl;
	    out_train.push_back(e);
	    in_train.pop_back();
	}
    }
    
    
    while(out_train.empty() != true){
        int e = out_train.front();
        std::cout << e << std::endl;
        out_train.erase(out_train.begin());
    }
    
    return 0;
}

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

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

	do{
		int in;
		std::cin >> in;

		if(in == 0){
			std::cout << trains.top() << std::endl;
			trains.pop();
		}
		else
			trains.push(in);
	}while(!trains.empty());
	return 0;
}

C++: #include<stdio.h>

int main(){
	int car[11],i=0,n;
	while(1){
		if(scanf("%d",&n)==EOF)break;
		if(n){
			car[i]=n;
			i++;
		}else{
			i--;
			printf("%d\n",car[i]);
			
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
#include <stack>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

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

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

int main(){
	int a[100]={0};int n=0;
	while(cin>>a[n++]);n--;
	int b[10]={0};
	for(int i=0;i<n;i++)
	{
		if(a[i]==0)
		{
			cout<<b[0]<<endl;
			for(int j=0;j<10;j++)
			{
				b[j]=b[j+1];
			}
		}else
		{
			for(int j=9;j>0;j--)
			{
				b[j]=b[j-1];
			}
			b[0]=a[i];
		}
	}
	return 0;
}

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