Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	n, err := strconv.Atoi(nextString())
	return n, err
}

func main() {
	scanner.Split(bufio.ScanWords)

	stack := []int{}
	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		if n == 0 { // pop
			fmt.Println(stack[len(stack)-1])
			stack = stack[0:(len(stack) - 1)]
		} else { // push
			stack = append(stack, n)
		}
	}
}

C++: #include<stdio.h>
const int SIZE=100;
int data[SIZE];
int sp=0;
int size(){
  return sp;
}
int empty(){
  return sp<=0;
}
int top(){
  return data[sp-1];
}
void pop(){
  sp--;
}
void push(int v){
  data[sp]=v;
  sp++;
}
int main(){
  int n,k;
  while(n!=EOF){
    scanf("%d",&n);
    if(n==0){
      printf("%d\n",top());
      pop();
    }else{
      push(n);
    }
  }
  return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
	int in[10];
	int i = 0;

	while (scanf("%d", &in[i]) != EOF){
		if (in[i] == 0){
			i--;
			printf("%d\n", in[i]);
		}
		else {
			i++;
		}
	}
}

C++: #include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;
int main(){
  int train[10],n,i;
  n = 0;
  int order[30],intrain[10];
  for( i = 1;i <= 10;i++){
    train[i] = i;
  }
  for(i=0;i<30;i++)
    order[i] = 11;
  i = 0;
  while(scanf("%d",&order[i]) != EOF){i++;}
  for(i = 0;order[i] != 11;i++){
    if(order[i] != 0){
      intrain[n] = order[i]; n++;}else if(order[i] == 0){
      n--;      cout << intrain[n] << endl;}
  }
}

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

using namespace std;

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

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;




signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	deque<int> d;
	while (1) {
		int k;
		cin >> k;
		if (cin.eof()) break;
		if (k == 0) {
			cout << d.back() << endl;
			d.pop_back();
		}
		else {
			d.push_back(k);
		}
	}
}

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