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

C++: /*****include*****/
#include <iostream>
#include <fstream>
#include <list>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	list<int> V;
	int order;
	/*****処理部*****/
	while(1){
		cin >> order;
		if(order == 0){
			cout << V.back() << endl;
			V.pop_back();
		}else{
			V.push_back(order);
		}
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

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

int main(){
	int a[100];
	int i = 0;
	while (cin >> a[i]){
		if (a[i] == 0){
			int j = i;
			while (1){
				j--;
				if (a[j] != 0){
					cout << a[j] << endl;
					a[j] = 0;
					break;
				}
			}
		}
		i++;
	}
	
	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(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;	
}