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

}

C++: //C++ツづ可偲?堕閉つウツづェツづ?つ「ツづゥツスツタツッツクツづーツ使ツつヲツづ篠甘按単
#include <iostream>
#include <stack>
using namespace std;

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

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

C++: #include <iostream>

using namespace std;

int main(){
  short stack[10]={0},turn[10]={0};
  short *pstack=stack,*pturn=turn;
  while(1){
    int num;
    cin>>num;
    if(num){
      *pstack=num;
      pstack++;
    }else{
      pstack--;
      *pturn=*pstack;
      pturn++;
    }
    if(pstack==stack) break;
  }
  for(pturn=turn;*pturn;pturn++)
    cout<<*pturn<<endl;
}

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

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

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 <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>

using namespace std;

int main() {

	stack<int> st;
	int a, ans[100]={0},i = 0;

	while (1) {
		cin >> a;
		if (a == 0) {
			ans[i] = st.top();
			st.pop();
			i++;
			if (st.empty())
				break;
		}
		else {
			st.push(a);
		}
	}

	for (int j = 0; j < i; j++) {
		cout << ans[j] << endl;
	}

	return 0;
}

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

using namespace std;
int main(int ac, char **av) {
  stack<int> st;
  int t;

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

C++: #include<iostream>
using namespace std;
int b[1000000];
int main(){
  int i=0,num,a[10],x=0;
  
  while(cin>>num){
    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;
}