Problem p00013 (C++) — buggy submission, verdict: Runtime Error

/*
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 <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#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
  int n;
  stack<int> T;
  vector<int> V;
  while (cin >> n) {
    if (n == 0) {
      V.push_back(T.top());
      T.pop();
    } else
      T.push(n);
  }
  FOR(a, V) cout << *a << endl;
  return 0;
}

Error: -11

Fixed submission:

/*
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 <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

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