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 <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < n; i++){
const int INF = 1 << 25;
 
stack<int> cars;
int numbar;
 
int main(){
    while(scanf("%d", &numbar) != EOF){
        if(numbar == 0){
            printf("%d\n", cars.top());
            cars.pop();
            continue;
        }
        cars.push(numbar);
    }
    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 <vector>

using namespace std;

int main() {
	vector<int> cars, ans;
	int temp, i=0, s=0, m;
	while (cin >> temp) {
		if (temp != 0) {
			cars.push_back(temp);
			i++;
		} else {
			m = i-s;
			ans.push_back(cars.at(m));
			s++;
		}
	}
	for (int j=0; j<ans.size(); j++)
		cout << ans[j] << endl;
	return 0;
}

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

int main(){
	vector<int> v;
	stack<int> s;
	int n;
	cin >> n;
	s.push(n);
	while(!s.empty()){
		cin>>n;
		if(n==0){
			v.push_back(s.top());
			s.pop();
		} else {
			s.push(n);
		}
	}
	for(int i=0 ; i<v.size(); i++){
		cout << v[i] << endl;
	}
	return 0;	
}

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

long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}
long long int lca(long long int l, long long int r) {
	return l / gcd(l, r)*r;
}
int getans(const int num, const int rest) {
	if (rest) {
		int ans = 0;
		for (int i = 0; i <= 9; ++i) {
			if (num >= i) {
				ans += getans(num - i, rest - 1);
			}
		}
		return ans;
	}
	else {
		return num == 0;
	}
}
int main() {
	int N;
	stack<int>sta;
	while (cin >> N) {
		
		if (N) {
			sta.emplace(N);
		}
		else {
			cout << sta.top() << endl;
			sta.pop();
		}
	}
	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 if(1 <= num && num <= 10){
      push(num);
    }
    if(size() == 0) break;
  }
  return 0;
}

C++: #include<stdio.h>

int main(){
  int i = 0, x, count = 0;
  int data[100];
  while(count < 0){
    scanf("%d\n", x);
    data[i] = x;
    if(x == 0){
      count--;
      i--;
      if(count >= 0){
        printf("%d\n", data[i-1]);
      }
    }else{
      count++;
      i++;
    }
  }
  return 0;
}

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

int main(){
stack<int>a;
int b;
scanf("%d",&b);
a.push(b);
while(a.size()){
	scanf("%d",&b);
	if(b)a.push(b);
	else {printf("%d\n",a.top());a.pop();}
}
}

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

using namespace std;

int main()
{
	int train;
	stack<int>station;
	while (scanf("%d", &train) != EOF)
	{
		if (train == 0)
		{
			printf("%d\n", station.top());
			station.pop();
		}
		else
		{
			station.push(train);
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int i;
	int box[51];
	i=-1;
	while(1){
		//cout<<i<<endl;
		cin>>n;
		if(cin.eof())	break;
		if(n==0){
			cout<<box[i]<<endl;
			i--;
		}
		else{
			i++;
			box[i]=n;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int train;
  stack<int> stay;
  while(cin>>train){
    if(train==0){
      cout<<stay.top()<<endl;
      stay.pop();
    }else
    stay.push(train);
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

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

C++: #include <cstdio>

using namespace std;

int main()
{
	int num, tmp[10] = {0}, num_out[100] = {0};
	int cnt_1 = 9, cnt_2 = 0;
	
	while (scanf("%d", &num) != EOF){
		if (num == 0){
			num_out[cnt_2] = tmp[cnt_1 + 1];
			//printf("num_out[%d]=%d\n", cnt_2, num_out[cnt_2]);
			cnt_2++;
			cnt_1++;
		}
		else {
			tmp[cnt_1] = num;
			//printf("tmp[%d]=%d\n", cnt_1, tmp[cnt_1]);
			cnt_1--;
		}
	}
	
	for (int i = 0; i < 100; i++){
		if (num_out[i] != 0){
			printf("%d\n", num_out[i]);
		}
	}
	
	return (0);
}

C++: #include<bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く 
　　提出する問題を間違えない */
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
int main(){
  stack<int> train;
  int a;
  while(1){
    cin >> a;
    if(a != 0){
      if(cin.eof())break;
      train.push(a);
    }else{
      cout << train.top() << endl;
      train.pop();
    }
  }
}

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

using namespace std;

stack<int> s;
int ac;

int main(void) {
    while(~scanf("%d", &ac)) {
        if(ac == 0) {
            cout << s.top() << endl;
            s.pop();
        } else {
            s.push(ac);
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-6;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    int n;
    queue<int> q;
    while(cin>>n){
        if(n==0){
            cout<<q.front()<<endl;
            q.pop();
        }else{
            q.push(n);
        }
    }
}

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

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

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