Go: package main

import "fmt"

func main() {
	stack := []int{}
	for {
		var a int
		i, _ := fmt.Scan(&a)
		if i == 0 {
			break
		}
		if a == 0 {
			fmt.Println(stack[len(stack)-1])
			stack = stack[:len(stack)-1]
			continue
		}
		stack = append(stack, a)
	}
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);

    stack<uint> carbarn;
    carbarn.push(0);            // dummy
    uint input;

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

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

int main(void){
  using namespace std;
  
  std::vector <int> train; 
  
  int temp;
  
  while(1){
    cin >> temp;
    if(cin.eof()){break;}


    if(temp!=0){
      train.push_back(temp);
    }

    else if(temp==0)
    {
      int last=train.back();
      train.pop_back();
      cout << last << endl;
    }

  }

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

C++: #include<stdio.h>
#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<stack>

using namespace std;
long long int num;
stack<int> s;

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

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

using namespace std;


int main(){
	stack<char> stk;
	char c;
	while (cin >> c){
		if (c == '0'){
			cout << stk.top() << endl;
			stk.pop();
		}
		else{
			stk.push(c);
		}
	}
	return 0;

}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b){
   int tmp;
   while(a%b==0){
      tmp=a%b;
      a=b;
      b=tmp;
   }
}

int lcm(int a,int b){
   return a*b/gcd(a,b);
}

bool prime_number(int n){
   if(n < 2){
      return false;
   }
   else if(n == 2){
      return true;
   }
   if(n % 2 == 0){
      return false;
   }
   for(int i=3;i<=n/i;i+=2){
      if(n % i == 0) return false;
      return true;
   }
}

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

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

int main()
{
  int n, i = 0, j = 0;
  int car[10] = {1};
  int output[10];
  while(cin >> n){
    if(n == 0){
      output[j] = car[i - 1];
      car[i - 1] = 0;
      i--;
      j++;
      if(i == 0)
	break;
    }else{
      car[i] = n;
      i++;
    }
  }
  for(int i = 0; i < j; i++){
    cout << output[i] << endl;
  }
}

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

int main(void){
	std::vector<int> trainID; //list of inputted trainID
	int tmp;

	std::cin >> tmp; //input trainID
	trainID.push_back(tmp); //add trainID

	while(!(trainID.empty())){ //LOOP
		std::cin >> tmp; //input trainID or 0

		if(tmp == 0){
			std::cout << trainID.back() << std::endl; //output last trainID
			trainID.pop_back(); //delete outputted trainID
		}else{
			trainID.push_back(tmp); //add trainID
		}
	}

	return 0;
}

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

int main(void){
    int no;
    std::stack<int> st;
    do{
        std::cin>>no;
        if(no==0){
            std::cout<<st.top()<<std::endl;
            st.pop();
        }else{
            st.push(no);
        }
    }while(!st.empty());
    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    stack<int> s;
    while (cin >> n) {
        if (n == 0) {
            cout << s.top() << "\n";
            s.pop();
        } else {
            s.push(n);
        }
    }
    return 0;
}

C++: #include<stdio.h>
int main(){
  int sp=0,data[100],n;
  while(1){
    scanf("%d",&n);
    if(n==0){
      sp--;
      printf("%d\n",data[sp]);
    }else{
      data[sp]=n;
      sp++;
    }
  }
}

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

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

  return 0;
}