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<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

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

	}

	ret 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void)
{
    int a[201][2] ={0};
    int i = 0,j = 0,k = 0,l = 0;
    int answer[201] = {0};
    bool judge = true;
    int tempjudge = 0;
    
    while(judge)
    {
        cin >> a[i][0];
        if(a[i][0] == 0)
        {
            a[i][1] = 1;
            RFOR(j,i,-1)
                if(a[j][1] != 1 )
                {
                    answer[l] = a[j][0];
                    a[j][1] = 1;
                    cout <<  answer[l] << endl;
                    l++;
                    break;
                }
        }
        REP(k,i+1)
        if(a[k][1] != 1){
                judge = true;
                break;
        }
        else
            judge = false;
                
        
        i++;
    }

    return 0;
}

C++: #include <stdio.h>

int train[10];
int sp = 0;

int empty() {
  return sp <= 0;
}

int size() {
  return sp;
}

int top() {
  return train[sp-1];
}

void pop() {
  sp--;
}

void push(int v) {
  train[sp] = v;
  sp++;
}

int main(){
  int num;
  while(1){
    scanf("%d", &num);
    if(num == 0){
      printf("%d\n", top());
      pop();
    }else{
      push(num);
    }
    if(size() = 0) break;
  }
  return 0;
}

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

int main() {
int k=0,b;
int a[100000000];
while(cin>>b){
	if(b!=0){
		a[k]=b;
		k=k+1;
	}
	if(b==0){
		cout<<a[k-1]<<endl;
		k=k-1;
	
}
}
	return 0;
}

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

class Stack
{
  private:
     int arr[102];
     int index;
  public:
    Stack()
   {
      index=0;
   }
   void push(int data)
   {
       arr[index]= data;
       index++;
   }
   int pop()
   {
       index--;
       return arr[index];
   }



};

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

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

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

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

int main() {
	int n, count = 0, a[10], i;
	stack<int> s;
	while (cin >> n,n>=0,!cin.eof()) {
		if (n > 0) s.push(n);
		else if (n == 0) { a[count++] = s.top(); s.pop(); count++;}
	}
	for (i = 0; i < count; i++) {
		cout << a[i] << endl;
	}
}

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(100000), ans;
	int temp, i=0, m;
	while (cin >> temp) {
		if (temp != 0) {
			cars[i] = temp;
			i++;
		} else {
			int p = i-1;
			if (p >= 0) {
				ans.push_back(cars[p]);
				i--;
			}
		}
	}
	for (int j=0; j<ans.size(); j++)
		cout << ans[j] << endl;
	return 0;
}

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

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

	return 0;
}

C++: #include <cstdio>
#include <queue>

using namespace std;

int main(){
  deque<int> que;
  int n;
  while(~scanf("%d",&n)){
    if(n){
      que.push_back(n);
    }else{
      printf("%d\n",que.back());
      que.pop_back();
    }
  }
}

C++: #include <stack>

#include <stdio.h>

int main(int argc, char** argv)
{
  std::stack<int> stack;

  int i;

  while (fscanf(stdin, "%d", &i) == 1) {
    if (i) {
      stack.push(i);
    }
    else {
      fprintf(stdout, "%d\n", stack.top());
      
      stack.pop();
    }
  }
}

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

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

    long long int n;
    std::stack<long long int> s;

    while (std::cin >> n) {
        if (n) {
            s.push(n);
        }
        else {
            std::cout << s.top() << std::endl;
            s.pop();
        }
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

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

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

int main(){
	int n[100],k;
	
	k=0;
	while(cin >> n[k]){
		if(n[k]==0){
			cout << n[k-1] << "\n";
			k--;
		}
		else{
			k++;
		}
	}
		
return 0;
}

C++: #include <stack>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	stack<int> a;
	vector<int> o;
	int s=1,d;
	cin>>d;
	a.push(d);
	while(s!=0){
		cin>>d;
		if(d!=0) {
			a.push(d);
			s++;
		}
			else {
				s--;
				o.push_back(a.top());
				a.pop();
			}
	}
	for(int i=0;i<o.size();i++) cout<<o[i]<<endl;
}

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

using namespace std;

int main(){

  int train;
  stack<int> s;

  while(cin >> train){
    if(train) s.push(train);
    else {
      cout << s.top() << endl;
      s.pop();
    }
  }

}