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<iostream>
#include<stack>
using namespace std;

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

C++: #include <cstdio>

int stack[10];
int cur = 0;

void push(int x){
	stack[cur] = x;
	cur++;
}

int pop(){
	cur--;
	return stack[cur];
}

int main(){
	int n;
	
	scanf("%d", &n);
	push(n);
	for(;;){
		scanf("%d", &n);
		if(n == 0){
			printf("%d\n", pop());
		}else {
			push(n);
		}
		if(cur == 0) break;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	stack<int> st;
	int x;
	while (cin >> x) {
		if (x == 0) {
			cout << st.top(); st.pop();
		}
		else st.push(x);
	}
}

C++: #include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<stack>
#include<set>
#include<cmath>

#define REP(i,s,e) for(int i=int(s);i<int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)

#define EPS 1e-6

using namespace std;

int main(){

	stack<int>cars;

	int a;
	while(true){

	cin >> a;
	if(cin.fail()) break;

	if(a!=0) cars.push(a);
	else{
	     cout << cars.top() << endl;
	     cars.pop();
	}
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>
#include <stack>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int in;
  stack<int> s;

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

  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>
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);
		}
	}
}

C++: #include<stdio.h>
int i=0,j=0;
int cars[19];

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

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

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

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

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

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

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num==0) pop();
		else push(num);
	}

    return 0;
}

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

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

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int now=-1;//0ツガツキツつスツづつォツづ可偲ヲツづィツ出ツつキツづ猟つォツ配ツ療ア
	int n[10]={0};
	int in;
	//for(;;){
		while(cin>>in){
		if(in==0){
			cout<<n[now];
			now--;
			if(now==-1)return 0;
		}
		else{
			n[now+1]=in;
			now++;
		}
	}
}

C++: #include<cstdio>
#include<stack>
#include<iostream>
int main()
{
  using namespace std;
  int input;
  stack<int> st;
  while(~scanf("%d",&input))
    {
      if(input == 0)
        {
          cout<<st.top()<<endl;
          st.pop();
        }else
        {
          st.push(input);
        }
    }
  return 0;
}

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

using namespace std;


int main (int argc, char const* argv[]){
    stack<int> st;
    int n;
    int tmp;
    list<int> list1;
    
    while((cin >> n)){
        if(n == 0){ 
            list1.push_back(st.top());
            st.pop();
        }
        else st.push(n);
    }
    
    list<int>::iterator it = list1.begin();
    while(it != list1.end()){
        cout << *it << endl;
        it++;
    }
    
    return 0;
}

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

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

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

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

std::array<u_int, 100> stack;
int point=0;

void push(int p){
	stack[point]=p;
	++point;
}

void pop(){
	std::cout << stack[point] << std::endl;
	--point;
}

int main(){
	int num;

	for(int i=0;i<100;i++){
		std::cin >> num;
		if(num==0 && point>=0) pop();
		else push(num);
	}

    return 0;
}