Go: package main

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

type Railway struct {
	trains trains
}

type trains []int

func main() {
	var stdin string
	var s = bufio.NewScanner(os.Stdin)

	railway := Railway{}
	for s.Scan() {
		stdin = s.Text()

		n, err := strconv.Atoi(stdin)
		if err != nil {
			continue
		}
		railway.lifo(n)
	}
}

func (r *Railway) lifo(n int) {
	if n == 0 {
		if len(r.trains) == 0 {
			return
		}
		fmt.Println(r.trains[len(r.trains)-1])
		r.trains = r.trains[:len(r.trains)-1]
	} else {
		r.trains = append(r.trains, n)
	}
}

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

int main(){
	std::stack<int> railroad;
	
	int incar;
	while(std::cin >> incar){
		if(incar != 0){
			railroad.push(incar);
		}else{
			std::cout << railroad.top() << std::endl;
			railroad.pop();
		}
	}
	return 0;
}

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

int main(){
  std::stack<int> train;
  int num;
  while(std::cin >> num){
    if(num != 0){
      train.push( num );
    }
    else {
      std::cout << train.top() << std::endl;
      train.pop();
    }
  }
  return 0;
}

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

int main() {
	int n, count = 0, a[11], i;
	stack<int> s;
	while (cin >> n) {
		if (n > 0) s.push(n);
		else if (n == 0) {
			a[count++] = s.top();
			s.pop();
		}
	}
	for (i = 0; i < count; i++) {
		cout << a[i] << endl;
	}
}

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

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

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
main(){
	int t[101],co=0;
	for(int i=0;i<=100;++i)t[i]=0;
	while(cin>>t[co]){
		if(t[co]==0){
			--co;
			cout<<t[co]<<endl;
		}else ++co;
	}
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <stack>
using namespace std;
int main(){
  int n;
  stack<int> in,out;
  while(cin>>n){
    if(!n)out.push(in.top()),in.pop(),cout<<out.top()<<endl;
    else{in.push(n);}
    if(in.empty()&&!out.empty())return 0;
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

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

C++: //include---------------------------------------------------------------------------
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cctype>
#include<ccomplex>
#include<vector>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<algorithm>
#include<memory>

//using namespace-------------------------------------------------------------------
using namespace std;

//define,const----------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < n; i++){
const int INF = 1 << 25;

//global----------------------------------------------------------------------------
stack<int> cars;
int numbar;

//function--------------------------------------------------------------------------
int main(){
	while(scanf("%d", &numbar) != EOF){
		if(numbar == 0){
			printf("%d\n", cars.top());
			cars.pop();
			continue;
		}
		cars.push(numbar);
	}
	return 0;
}

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

using namespace std;
int main(){
    stack<int> stop;
    int come;
    while(cin >> come){
        if(come!=0) stop.push(come);
        else{
            cout << stop.top() << endl;
            stop.pop();
        }
    }
    return 0;
}

C++: /*
NOTE :
*min_element(.begin(),.end())
*max_element(.begin(),.end())
stack push pop top
queue push pop front
priority_queue<> pq
 push()  pop() size()  top()
map<>
 find() begin() end() insert(map<>::value_type())
pair<>
sort(.begin(), .end())
sort(arr, arr+N)
sort(a, a+N, greater<int>())
binary_search(vc.begin(), vc.end(), x)  //binary_search???true, false?????????
vector<int>::iterator lit = lower_bound(vc.begin(), vc.end(), x);
  lower_bound?????????????????????"??\???"????????????????????????????????????????????¬???????????????
vector<int>::iterator uit = upper_bound(vc.begin(), vc.end(), x);
  upper_bound????????????????????????"?¶???????"?????????????????????????????????????????¬???????????????
*/
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <valarray>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

#define MAX 100
#define INF 1<<20
#define LLINF 10e12 // 1<<31 // 2^31
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,a,n) for(int i=(a);i<(n);i++)
#define SET(a,c) memset(a,c,sizeof a)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique(ALL((o))), (o).end());

using namespace std;
typedef long long ll;
typedef valarray<int> array_t;
/////

/////
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // FROM HERE
  stack<int> T;
  do
  {
    int n; cin >> n;
    if(n == 0)
    {
      cout << T.top() << endl;
      T.pop();
    }
    else T.push(n);
  }
  while(!T.empty());
  return 0;
}

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

int main() {

  vector<long long int> num;
  long long int input;

  while( cin >> input ) {

    if ( input != 0 ) {

      num.push_back(input);

    }else {

      cout << num[ num.size()-1 ] << endl;
      num.pop_back();

    }

  }

  return 0;

}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int in[10] = {0},out[10];
	int n;
	int i = 0;
	int j = 0;
	while(scanf("%d",&n) != EOF){
		if(n != 0){
			in[i] = n;
			i++;
		}
		else {
			i--;
			out[j] = in[i];
			j++;
			in[i] = 0;
		}
	}
}

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

stack <int> s;
int k;
int ans;

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

C++: #include<iostream>
using namespace std;
int main(){
  
  int a[10],c=0,num;

  while(1){

    cin >>num;

    if(num >= 1 && num <=10){
      a[c]=num;
      c++;
    }else if(num == 0){
      cout <<a[c-1]<<endl;
      c--;
    }   

  }
  return 0;

}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


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