alexjercan/bugnet huggingface dataset:
Problem p00012 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  double vx1, vy1, vx2, vy2, vxp, vyp;
  double s, t;
  while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    vx1 = x2 - x1;
    vy1 = y2 - y1;
    vx2 = x3 - x1;
    vy2 = y3 - y1;
    vxp = xp - x1;
    vyp = yp - y1;
    s = (vyp * vx2 - vxp * vy2) / (vy1 * vx2 - vx1 * vy2);
    if (vx2) {
      t = (vxp - vx1 * s) / vx2;
    } else {
      t = (vyp - vy1 * s) / vy2;
    }

    if (s > 0.0 && t > 0.0 && s + t < 1.0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <utility>
using namespace std;

int main() {
  int n;
  cin >> n;
  while (1) {
    bool ans = true;
    double x[3], y[3], xp, yp;
    cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> xp >> yp;
    if (!x[0] && !x[1] && !x[2] && !y[0] && !y[1] && !y[2] && !xp && !yp)
      break;
    //???????????¨????????????
    double gaiseki
        [3]; // gaiseki[i]???????????????P0P1??¨????????????P0Q????????????z??§?¨?
    for (int i = 0; i < 3; i++) {
      int k = (i + 1) % 3;
      double vx, vy, vpx, vpy;
      vx = x[k] - x[i];
      vy = y[k] - y[i];
      vpx = xp - x[i];
      vpy = yp - y[i];
      gaiseki[i] = vx * vpy - vy * vpx;
      if (gaiseki[i] <= 0)
        ans = false;
    }
    if (ans) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
Problem p00012 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

int main() {

  double x[4], y[4];
  while (cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]) {
    double a[3], b[3], c[3], d[3];
    for (int i = 0; i < 3; i++) {
      a[i] = x[(i + 1) % 3] - x[i];
      b[i] = y[(i + 1) % 3] - y[i];
    }
    for (int i = 0; i < 3; i++) {
      c[i] = x[3] - x[i];
      d[i] = y[3] - y[i];
    }
    int suc = 1;
    for (int i = 0; i < 3; i++) {

      if ((a[i] * b[(i + 1) % 3] - a[(i + 1) % 3] * b[i]) *
              (a[i] * d[(i + 1) % 3] - c[(i + 1) % 3] * b[i]) <
          0) {
        suc = 0;
        break;
      }
    }
    if (suc == 0)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

int main() {

  double x[4], y[4];
  while (true) {
    REP(i, 4) {
      cin >> x[i];
      if (cin.eof())
        break;
      cin >> y[i];
    }
    double s, t;
    bool flg = false;
    REP(i, 1e6) {
      s = ((double)i / 1e6);
      t = (double)1 - s;
      double x1 = s * (x[2] - x[0]) + t * (x[1] - x[0]);
      double y1 = s * (y[2] - y[0]) + t * (y[1] - y[0]);
      double x2 = x[3] - x[0];
      double y2 = y[3] - y[0];
      double dotpro = (((x1 * x2 + y1 * y2) * (x1 * x2 + y1 * y2)) /
                       ((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2)));
      // cout << dotpro << endl;
      if (1 - dotpro <= 1e-3) {
        flg = true;
        break;
      }
    }
    if (flg)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>

using namespace std;

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

Error: -11

Fixed submission:

#include <iostream>
#include <stack>

using namespace std;

int main() {
  stack<int> st;
  int a, i;
  for (i = 0; i < 100; i++) {
    cin >> a;
    if (a == 0) {
      cout << st.top() << endl;
      st.pop();
    } else {
      st.push(a);
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp = 0;
int size() { return sp; }
int empty() { return sp <= 0; }
int top() { return data[sp - 1]; }
void pop() { sp--; }
void push(int v) {
  data[sp] = v;
  sp++;
}
int main() {
  int n, k;
  while (scanf("%d", &n) != EOF) {
    if (n == 0) {
      printf("%d\\n", top());
      pop();
    } else {
      push(n);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp = 0;
int size() { return sp; }
int empty() { return sp <= 0; }
int top() { return data[sp - 1]; }
void pop() { sp--; }
void push(int v) {
  data[sp] = v;
  sp++;
}
int main() {
  int n, k;
  while (n != EOF) {
    scanf("%d", &n);
    if (n == 0) {
      printf("%d\\n", top());
      pop();
    } else {
      push(n);
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <deque>

using namespace std;

int main() {
  deque<int> st;
  int n;
  while (~scanf("%d", &n)) {
    if (n) {
      st.push_back(n);
    } else {
      printf("%d\\n", st.back());
      st.pop_back();
    }
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
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;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <stack>

using namespace std;

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

Error: -11

Fixed submission:

#include <iostream>
#include <stack>

int main() {
  int n;
  std::stack<int> st;
  while (1) {
    std::cin >> n;
    if (n == 0) {
      std::cout << st.top() << std::endl;
      st.pop();
    } else {
      st.push(n);
    }
    if (std::cin.eof())
      break;
  }
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main() {
  int g[10];
  int i = 0;
  int t;
  while (scanf("%d", &t) + 1) {
    if (t) {
      g[i] = t;
      i++;
    } else {
      i--;
      printf("%d\\n", g[i]);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>

int main() {
  int g[10];
  int i = 0;
  int t;
  while (scanf("%d", &t)) {
    if (t) {
      g[i] = t;
      i++;
    } else {
      i--;
      printf("%d\\n", g[i]);
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
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 <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> cars(100000), ans;
  int temp, i = 0, m;
  while (cin >> temp) {
    if (temp != 0) {
      cars[i] = temp;
      i++;
    } else {
      int p = i - 1;
      if (p >= 0) {
        ans.push_back(cars[p]);
        i--;
      }
    }
  }
  for (int j = 0; j < ans.size(); j++)
    cout << ans[j] << endl;
  return 0;
}

Error: TLE

Fixed submission:

/*
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 <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> cars(100000), ans;
  int temp, i = 0, m;
  while (scanf("%d\\n", &temp)) {
    if (temp != 0) {
      cars[i] = temp;
      i++;
    } else {
      int p = i - 1;
      if (p < 0) {
        ans.push_back(cars[p]);
        i--;
      }
    }
  }
  for (int j = 0; j < ans.size(); j++)
    cout << ans[j] << endl;
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> v;
  vector<int>::iterator pv = v.begin();
  int n;
  while (cin >> n) {
    if (n == 0) {
      int x = v.size();
      cout << v[x - 1] << endl;
      v.pop_back();
      continue;
    }
    v.push_back(n);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> v;
  vector<int>::iterator pv = v.begin();
  int n;
  while (1) {
    cin >> n;
    if (n == EOF) {
      break;
    }
    if (n == 0) {
      pv = v.end();
      cout << *pv << endl;
      pv = v.begin();
      v.pop_back();
    }
    v.push_back(n);
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include "stdio.h"
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int input;
  int input_order[100];
  stack<int> train_stack;
  vector<int> order;

  while (~scanf("%d", &input)) {
    if (input == 0) {
      cout << train_stack.top() << endl;
      train_stack.pop();
    } else {
      train_stack.push(input);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int input;
  stack<int> train_stack;
  vector<int> order;

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

  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>

using namespace std;

int main(void) {
  int tem;
  stack<int> st;
  cin >> tem;
  st.push(tem);
  while (true) {
    cin >> tem;
    if (cin.eof())
      break;
    if (tem)
      st.push(tem);
    else {
      cout << st.top() << endl;
      st.pop();
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stack>

using namespace std;

int main(void) {
  int tem;
  stack<int> st;
  cin >> tem;
  st.push(tem);
  while (true) {
    if (cin.eof())
      break;
    cin >> tem;
    if (tem)
      st.push(tem);
    else {
      cout << st.top() << endl;
      st.pop();
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stack>
using namespace std;

int main() {
  stack<int> sta;
  int temp;

  while (cin >> temp) {
    if (temp == 0) {
      if (sta.empty() == false) {
        cout << sta.top() << endl;
        sta.pop();
      }
    } else {
      sta.push(temp);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stack>
using namespace std;

int main() {
  stack<int> sta;

  while (1) {

    int temp;
    cin >> temp;

    if (temp == 0) {
      if (sta.empty() == false) {
        cout << sta.top() << endl;
        sta.pop();
      }
    } else {
      sta.push(temp);
    }
  }

  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <cassert>
#include <iostream>
#include <stack>

int main() {
  std::stack<int> Stack;
  while (true) {
    int n;
    std::cin >> n;
    if (std::cin.eof())
      break;
    if (n == 0) {
      assert(Stack.empty() == false);
      std::cout << Stack.top() << std::endl;
      Stack.pop();
    } else {
      Stack.push(n);
    }
  }
  return 0;
}

Error: -6
3e12593d-04c5-40a1-8916-32915c00c957.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00013/C++/s972317534.cpp:13: int main(): Assertion `Stack.empty() == false' failed.


Fixed submission:

#include <cassert>
#include <iostream>
#include <stack>

int main() {
  std::stack<int> Stack;
  while (true) {
    int n;
    std::cin >> n;
    if (n == 0) {
      assert(Stack.empty() == false);
      std::cout << Stack.top() << std::endl;
      Stack.pop();
    } else {
      Stack.push(n);
    }
    if (std::cin.eof())
      break;
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int k = 0, b;
  int a[1000000];
  while (cin >> b) {
    if (b != 0) {
      a[k] = b;
      k = k + 1;
    }
    if (b == 0) {
      cout << a[k - 1] << endl;
      k = k - 1;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int k = 0, b;
  int a[100000000];
  while (cin >> b) {
    if (b != 0) {
      a[k] = b;
      k = k + 1;
    }
    if (b == 0) {
      cout << a[k - 1] << endl;
      k = k - 1;
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <malloc.h>
using namespace std;

struct stack {
  int element;
  struct stack *next;
};
int top(struct stack *s) { return s->element; }
struct stack *pop(struct stack *s) {
  struct stack *p, *q;
  q = s;
  p = s->next;
  free(q);
  s = p;
  return s;
}
struct stack *push(struct stack *s, int x) {
  struct stack *p, *q;
  q = s;
  p = (struct stack *)malloc(sizeof(struct stack));
  p->element = x;
  p->next = q;
  s = p;
  return s;
}

int main() {
  struct stack *S = NULL;
  int num;
  while (cin >> num) {
    if (num == 0) {
      cout << top(S) << endl;
      S = pop(S);
    } else {
      S = push(S, num);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <malloc.h>
using namespace std;

struct stack {
  int element;
  struct stack *next;
};
int top(struct stack *s) { return s->element; }
struct stack *pop(struct stack *s) {
  struct stack *p, *q;
  q = s;
  p = s->next;
  free(q);
  s = p;
  return s;
}
struct stack *push(struct stack *s, int x) {
  struct stack *p, *q;
  q = s;
  p = (struct stack *)malloc(sizeof(struct stack));
  p->element = x;
  p->next = q;
  s = p;
  return s;
}

int main() {
  struct stack *S = NULL;
  int num;
  while (1) {
    cin >> num;
    if (num == 0) {
      cout << top(S) << endl;
      S = pop(S);
    } else {
      S = push(S, num);
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int temp[10];
  int input;

  int i = 0;

  while (scanf("%d", &input) != EOF) {
    if (input != 0) {
      temp[i] = input;
      i++;
    }

    else {
      i--;
      printf("%d\\n", temp[i]);
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  int input[20];
  int output[10];
  int temp[10];
  int i;
  int j = 0;
  int k = 0;

  for (i = 0; i < 20; i++)
    input[i] = 11;

  i = 0;
  while (scanf("%d", &input[i]) != EOF)
    i++;

  i = 0;
  while (input[i] != 11) {
    if (input[i] != 0) {
      temp[j] = input[i];
      j++;
    }

    else {
      j--;
      output[k] = temp[j];
      k++;
    }

    i++;
  }

  for (i = 0; i < k; i++)
    printf("%d\\n", output[i]);

  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n = 0;
  vector<int> a;

  while (cin >> n) {

    if (n == 0) {
      cout << a.back() << endl;
      a.pop_back();
    } else {
      a.push_back(n);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

int main() {

  vector<int> a;
  vector<int> b;
  vector<int> c;
  int s[20];
  while (true) {
    for (int i = 0; i < 20; i++) {
      cin >> s[i];

      if (s[i] == 0) {
        b.push_back(s[i]);
        a.push_back(c.back());
        c.pop_back();
        if (c.size() == 0) {
          break;
        }
      } else {
        c.push_back(s[i]);
      }
    }
    for (int j = 0; j < a.size(); j++)
      cout << a[j] << endl;
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int i = 0, j = 0;
int cars[19];

int main() {
  while (1) {

    if (scanf("%d", &cars[i]) == -1) {
      break;
    }
    if (cars[i] == 0) {
      printf("%d\\n", cars[i - 1]);
      i--;
    } else {
      i++;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int i = 0;
int cars[19];

int main() {
  while (1) {
    scanf("%d", &cars[i]);
    if (cars[i] == 0) {
      printf("%d\\n", cars[i - 1]);
      i--;
    } else {
      i++;
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int i = 0, x;
  int data[100];
  while (scanf("%d", &x) != EOF) {
    if (x != 0) {
      data[i] = x;
      i++;
    } else {
      printf("%d\\n", data[i - 1]);
      i--;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int i = 0, x;
  int data[100];
  scanf("%d", &x);
  while (x != EOF) {
    if (x != 0) {
      data[i] = x;
      i++;
    } else {
      printf("%d\\n", data[i - 1]);
      i--;
    }
    scanf("%d", &x);
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
using namespace std;
int main(void) {
  int num;
  stack<int> st;

  while (cin >> num) {
    st.push(num);
    if (num == 0) {
      st.pop(); // 0ツづーツ渉慊つュ
      cout << st.top() << endl;
      st.pop();
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stack>
using namespace std;
int main(void) {
  int num;
  stack<int> st;

  while (1) {
    cin >> num;
    st.push(num);
    if (num == 0) {
      st.pop(); // 0ツづーツ渉慊つュ
      cout << st.top() << endl;
      st.pop();
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
using namespace std;

int main() {
  int answer[10];
  int a, b;
  b = 0;
  stack<int> train;
  while (cin >> a) {
    if (a == 0) {
      cout << train.top() << endl;
      train.pop();
    }
    if (a != 0) {
      train.push(a);
    }
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <stack>
using namespace std;

int main() {
  int answer[10];
  int a, b;
  b = 0;
  stack<int> train;
  while (cin >> a) {
    if (a == 0) {
      answer[b] = train.top();
      b++;
      train.pop();
    }
    if (a != 0) {
      train.push(a);
    }
  }
  for (int i = 0; i < b; i++) {
    cout << answer[b] << endl;
  }
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
using namespace std;

int main() {
  int x;
  stack<int> S;
  while (1) {
    cin >> x;
    if (x == 0) {
      if (S.empty())
        break;
      cout << S.top() << endl;
      S.pop();
    } else {
      S.push(x);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stack>
using namespace std;

int main() {
  int x;
  stack<int> S;
  while (1) {
    cin >> x;
    if (x == 0) {
      cout << S.top() << endl;
      S.pop();
    } else {
      S.push(x);
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
using namespace std;

int main() {
  int num;
  stack<int> stack;

  while (cin >> num) {

    if (num == 0) {
      cout << stack.top() << endl;
      stack.pop();
    } else {
      stack.push(num);
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stack>
using namespace std;

int main() {
  int num;
  stack<int> st;

  while (!cin.eof()) {
    cin >> num;

    if (num == 0) {
      cout << st.top() << endl;
      st.pop();
    } else {
      st.push(num);
    }
  }

  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
using namespace std;
int main() {
  stack<int> chu;
  int i = 0;
  int input;
  int hairetu[111];
  cin >> input;
  chu.push(input);
  while (cin >> input) {
    if (input != 0) {
      chu.push(input);
    } else {
      hairetu[i] = chu.top();
      chu.pop();
      i++;
    }
  }
  for (int j = 0; j <= i - 1; j++) {
    cout << hairetu[j] << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <stack>
using namespace std;
int main() {
  stack<int> chu;
  int i = 0;
  int input;
  int hairetu[10];
  cin >> input;
  chu.push(input);
  while (cin >> input) {
    if (input != 0) {
      chu.push(input);
    } else {
      hairetu[i] = chu.top();
      chu.pop();
      i++;
    }
  }
  for (int j = 0; j <= i - 1; j++) {
    cout << hairetu[j] << endl;
  }
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>

using namespace std;

int main() {
  stack<int> line;
  int n;

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


Error: 0

Fixed submission:

#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main() {
  int data[10];
  stack<int> line;
  vector<int> top;
  int i = 0;

  while (cin >> data[i]) {
    ++i;
  }

  for (auto i : data) {
    if (i == 0) {
      top.push_back(line.top());
      line.pop();
    } else {
      line.push(i);
    }
  }

  for (auto t : top) {
    cout << t << endl;
  }

  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

Error: 0

Fixed submission:

#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++;
    } else {
      car[i] = n;
      i++;
    }
  }
  for (int i = 0; i < j; i++) {
    cout << output[i] << endl;
  }
}