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

C++: #include <iostream>
#include <algorithm>
#include<string>
using namespace std;
int top,s[10];
void push(int x){
    s[++top]=x;
}
void pop(){
    top--;
    cout<<s[top+1]<<endl;
}
int main(){
    int num;
    while(1){
        cin>>num;
        if(num==0)
            pop();
        else push(num);
    }
    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){
      if((i - 1) < 0)
	break;
      output[j] = car[i - 1];
      car[i - 1] = 0;
      i--;
      j++;
    }else{
      car[i] = n;
      i++;
    }
  }
  for(int i = 0; i < j; i++){
    cout << output[i] << endl;
  }
}

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

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>

using namespace std;

int main() {

	stack<int> st;
	int a, ans[100]={0},i = 0;

	while (scanf("%d",&a),a) {
		if (a == 0) {
			ans[i] = st.top();
			st.pop();
			i++;
		}
		else {
			st.push(a);
		}
	}

	for (int j = 0; j < i; j++) {
		cout << ans[j] << endl;
	}
	return 0;
}