alexjercan/bugnet huggingface dataset:
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a[10], i = 0, n;
  while (scanf("%d", &n) == 1) {
    if (n != 0) {
      a[i] = n;
      i++;
    } else {
      i--;
      cout << a[i] << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a[10], i = 0, n;
  while (scanf("%d", n) == 1) {
    if (n != 0) {
      a[i] = n;
      i++;
    } else {
      i--;
      cout << a[i] << endl;
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  stack<int> a;
  int b;
  scanf("%d", &b);
  a.push(b);
  while (cin >> b) {
    if (b)
      a.push(b);
    else {
      printf("%d\\n", a.top());
      a.pop();
    }
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  stack<int> a;
  int b;
  while (scanf("%d", &b)) {
    if (b)
      a.push(b);
    else {
      printf("%d\\n", a.top());
      a.pop();
    }
  }
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int train[10000], moving, situation = 0, ans[10000], n = 0, ende = 0;
  while (cin >> moving) {
    if (moving != 0) {
      train[situation] = moving;
      situation++;
    } else {
      situation--;
      ans[ende] = train[situation];
      ende++;
    }
  }
  for (int i = 0; i < ende; i++)
    cout << ans[i] << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int train[10], moving, situation = 0, ans[10], n = 0, ende = 0;
  while (cin >> moving) {
    if (moving != 0) {
      train[situation] = moving;
      situation++;
    } else {
      situation--;
      ans[ende] = train[situation];
      ende++;
    }
  }
  for (int i = 0; i < ende; i++)
    cout << ans[i] << endl;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int i = 0, num, a[10], x = 0;

  while (cin >> num) {
    if (num == 0)
      cout << a[--i] << endl;
    else
      a[i++] = num;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int i = 0, num, a[10], b[10], x = 0;

  while (cin >> num) {
    int count = 0;
    count++;
    if (num == 0) {
      b[x++] = a[i - 1];
      i--;
    } else
      a[i++] = num;
  }

  for (i = 0; i < x; i++)
    cout << b[i] << endl;
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>

using namespace std;

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

Error: -11

Fixed submission:

#include <iostream>
#include <stack>

using namespace std;

int main() {
  int n;
  stack<int> s;
  while (true) {
    cin >> n;

    if (n == 0) {
      cout << s.top() << endl;
      s.pop();
    } else {
      s.push(n);
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <deque>
#include <iostream>
#include <stack>
using namespace std;
int main() {
  int m, n;
  deque<int> deq;
  while (1) {
    cin >> n;
    if (cin.eof())
      break;
    if (n != 0)
      deq.push_back(n);
    else {
      if (deq.empty()) {
        continue;
      } else {
        cout << deq[(int)deq.size() - 1] << endl;
        deq.pop_back();
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <deque>
#include <iostream>
#include <stack>
using namespace std;
int main() {
  int m, n;
  deque<int> deq;
  while (1) {
    cin >> n;
    if (n != 0)
      deq.push_back(n);
    else {
      if (deq.empty()) {
        continue;
      } else {
        cout << deq[(int)deq.size() - 1] << endl;
        deq.pop_back();
      }
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: -11

Fixed submission:

#include <iostream>
#include <stack>

using namespace std;

stack<int> s;

int main() {

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

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

#include <iostream>
#include <stack>

using namespace std;

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


Error: TLE

Fixed submission:

#include <iostream>
#include <stack>

using namespace std;

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

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

int main() {
  stack<int> trains;
  int i;
  do {
    cin >> i;
    if (i != 0)
      trains.push(i);
    else {
      if (trains.empty())
        break;
      cout << trains.top() << endl;
      trains.pop();
    }
  } while (true);
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  stack<int> trains;
  int i;
  do {
    cin >> i;
    if (i != 0)
      trains.push(i);
    else {
      cout << trains.top() << endl;
      trains.pop();
    }
  } while (true); //! trains.empty());
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int car[11], i = 0, n;
  while (1) {
    if (scanf("%d", &n) == EOF)
      break;
    if (n) {
      car[i] = n;
      i++;
    } else {
      i--;
      printf("%d\\n", car[i]);
    }
  }
}

Error: -11

Fixed submission:

#include <stdio.h>

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

#include <bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く
　　提出する問題を間違えない */
#define ANSWER(x) cout << x << endl
#define debug(x) cout << #x << ": " << x
int main() {
  stack<int> train;
  int a;
  while (1) {
    cin >> a;
    if (a) {
      train.push(a);
    } else {
      if (cin.eof())
        break;
      cout << train.top() << endl;
      train.pop();
    }
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く
　　提出する問題を間違えない */
#define ANSWER(x) cout << x << endl
#define debug(x) cout << #x << ": " << x
int main() {
  stack<int> train;
  int a;
  while (1) {
    cin >> a;
    if (a != 0) {
      if (cin.eof())
        break;
      train.push(a);
    } else {
      cout << train.top() << endl;
      train.pop();
    }
  }
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {

  int n, m[12] = {};

  while (cin >> n) {
    if (cin.eof())
      break;
    if (n == 0) {
      for (int i = 11; i >= 0; i--) {
        if (m[i] != 0) {
          cout << m[i] << endl;
          m[i] = 0;
          break;
        }
      }
    } else {
      for (int i = 0; i < 12; i++) {
        if (m[i] == 0) {
          m[i] = n;
          break;
        }
      }
    }
  }

  return 0;
}

Error: -11

Fixed submission:

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

int main() {

  int n = 1;
  int x;
  stack<int> y;

  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x != 0) {
      n = n * 2;
      y.push(x);
    } else {
      cout << y.top() << endl;
      y.pop();
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;

int main() {

  int c[256], e[256], m, n = 0, k = 0;
  for (int i = 0; i < 10; i++) {
    c[i] = 0;
    e[i] = 0;
  }

  while (cin >> m) {
    if (m == 0) {
      e[k] = c[n - 1];
      k++;
      c[n - 1] = 0;
      n--;
    } else {
      c[n] = m;
      n++;
    }
  }

  for (int i = 0; i < k; i++)
    cout << e[i] << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;

int main() {

  int c[10], e[10], m, n = 0, k = 0;
  for (int i = 0; i < 10; i++) {
    c[i] = 0;
    e[i] = 0;
  }

  while (cin >> m) {
    if (m == 0) {
      e[k] = c[n - 1];
      k++;
      c[n - 1] = 0;
      n--;
    } else {
      c[n] = m;
      n++;
    }
  }

  for (int i = 0; i < k; i++)
    cout << e[i] << endl;

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

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a;
  vector<int> s;
  while (cin >> a) {
    if (a != 0) {
      s.push_back(a);
    } else if (a == 0) {
      cout << s[s.size() - 1] << endl;
      s.pop_back();
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a, c, i;
  vector<int> s;
  vector<int> t;
  while (cin >> a) {
    c = s.size();
    if (a != 0) {
      s.push_back(a);
    } else if (a == 0 && c > 0) {
      s.pop_back();
      t.push_back(s[s.size() - 1]);
      s.pop_back();
    }
  }
  int b = t.size();
  for (i = 0; i < b; i++) {
    cout << t[i] << endl;
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int num, top;
  int train[1024];
  int i;

  top = 0;

  while (scanf("%d", &num) != EOF) {
    if (num == 0) {
      printf("%d\\n", train[top - 1]);
      train[top - 1] = 0;
      top--;
    } else {
      train[top] = num;
      top++;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <stack>
#include <stdio.h>

int main() {
  int i = 0;
  std::stack<int> train;
  scanf("%d", &i);
  train.push(i);
  while (1) {
    scanf("%d", &i);
    if (i == 0) {
      printf("%d\\n", train.top());
      train.pop();
    } else {
      printf("%d\\n", train.top());
      train.pop();
      train.push(i);
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <stack>
#include <stdio.h>

int main() {
  int data[100], i = 0, n = 0;
  std::stack<int> train;
  while (scanf("%d", &data[i]) != EOF) {
    i++;
    n++;
  }
  i = 0;
  train.push(data[i]);
  for (i = 1; i < n; i++) {
    if (data[i] == 0) {
      printf("%d\\n", train.top());
      train.pop();
    } else {
      train.push(data[i]);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stack>
#include <stdio.h>

int main() {
  int data[100] = {0}, i = 0;
  std::stack<int> train;
  while (data[i] != EOF) {
    scanf("%d", &data[i]);
    i++;
  }
  i = 0;
  train.push(data[i]);
  i = 1;
  while (1) {
    if (!train.empty()) {
      if (data[i] == 0) {
        printf("%d\\n", train.top());
        train.pop();
      } else {
        train.push(data[i]);
      }
      i++;
    } else {
      break;
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int train[10] = {0}, n, count = 0, outTrain[10], trainCount = 0;
  while (cin >> n) {
    if (cin.eof())
      break;
    if (n) {
      for (int i = count; i != 0; i--) {
        train[i] = train[i - 1];
      }
      train[0] = n;
      count++;
    } else {
      outTrain[trainCount] = train[0];
      cout << train[0] << '\\n';
      for (int i = 0; i < count; i++) {
        train[i] = train[i + 1];
      }
      train[count] = 0;
      count--;
      trainCount++;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int train[10] = {0}, n, count = 0, outTrain[10], trainCount = 0;
  while (cin >> n) {
    if (cin.eof())
      break;
    if (n) {
      for (int i = count; i != 0; i--) {
        train[i] = train[i - 1];
      }
      train[0] = n;
      count++;
    } else {
      outTrain[trainCount] = train[0];
      for (int i = 0; i < count; i++) {
        train[i] = train[i + 1];
      }
      train[count] = 0;
      count--;
      trainCount++;
    }
  }
  for (int i = 0; i < trainCount; i++) {
    cout << outTrain[i] << '\\n';
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int t, s = 0;

  while (scanf("%d", &t), t) {
    int i, now = 0, count = 0;
    int train[12] = {0}, car[12] = {0};

    for (;;) {
      if (s != 0) {
        scanf("%d", &t);
      } else {
        s = 1;
      }
      if (t != 0) {
        train[now] = t;
        now++;
      } else {
        now--;
        car[count] = train[now];
        train[now] = 0;
        count++;
        if (now == 0)
          break;
      }
    }

    i = 0;
    while (car[i] != 0) {
      printf("%d\\n", car[i]);
      i++;
    }
    s = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main(void) {
  char tr[30];
  int i = 0, j, k, l, in[10] = {0}, out[10] = {0};
  while (scanf("%d", &tr[i]) != EOF) {
    i++;
  }

  for (j = 0, k = 0, l = 0; j < i; j++) {
    switch (tr[j]) {
    case 1:
      in[k] = 1;
      k++;
      break;
    case 2:
      in[k] = 2;
      k++;
      break;
    case 3:
      in[k] = 3;
      k++;
      break;
    case 4:
      in[k] = 4;
      k++;
      break;
    case 5:
      in[k] = 5;
      k++;
      break;
    case 6:
      in[k] = 6;
      k++;
      break;
    case 7:
      in[k] = 7;
      k++;
      break;
    case 8:
      in[k] = 8;
      k++;
      break;
    case 9:
      in[k] = 9;
      k++;
      break;
    case 10:
      in[k] = 10;
      k++;
      break;
    case 0:
      k--;
      out[l] = in[k];
      l++;
      break;
    default:
      break;
    }
  }
  for (i = 0; i < l; i++) {
    printf("%d\\n", out[i]);
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  stack<int> R;
  int n;
  int car[1000];
  int i = 0;

  while (cin >> n) {
    if (n == 0) {
      car[i] = R.top();
      R.pop();
      i++;
    } else {
      R.push(n);
    }
  }

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

  return (0);
}

Error: 0

Fixed submission:

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

int main() {
  stack<int> R;
  int n;
  int car[10];
  int i = 0;

  while (cin >> n) {
    if (n == 0) {
      car[i] = R.top();
      R.pop();
      i++;
    } else {
      R.push(n);
    }
  }

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

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

#include <stdio.h>

#define N 20
int main(void) {
  int stk[N], sp = 0;
  int n;

  while (scanf("%d", &n) != EOF) {
    if (n == 0 && sp != 0) {
      printf("%d\\n", stk[--sp]);
    } else {
      stk[sp++] = n;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

#define N 20
int main(void) {
  int stk[N], sp = 0;
  int n;

  while (scanf("%d", &n)) {
    if (n == 0 && sp != 0) {
      printf("%d\\n", stk[--sp]);
    } else {
      stk[sp++] = n;
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, l, n) for (i = l; i < n; i++)
using namespace std;

int main() {
  int data[15] = {}, i = 0, n;

  while (scanf("%d", &n) != EOF) {
    if (n != 0) {
      data[i] = n;
      i++;
    } else if (n == 0) {
      cout << data[i - 1] << endl;
      i--;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, l, n) for (i = l; i < n; i++)
using namespace std;

int main() {
  int data[15] = {}, i = 0, n;

  while (1) {
    cin >> n;
    if (n != 0) {
      data[i] = n;
      i++;
    } else if (n == 0) {
      cout << data[i - 1] << endl;
      i--;
    }
  }
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>

int main(int argc, char *argv[]) {
  std::stack<int> vec;
  int temp;

  while (std::cin >> temp) {
    if (temp == 0) {
      int a = vec.top();
      std::cout << a << std::endl;
      vec.pop();
      continue;
    } else {
      vec.push(temp);
      continue;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stack>

int main(int argc, char *argv[]) {
  std::stack<int> vec;

  while (!std::cin.eof()) {
    int temp;
    std::cin >> temp;
    if (temp == 0) {
      std::cout << vec.top() << std::endl;
      vec.pop();
      continue;
    } else {
      vec.push(temp);
      continue;
    }
  }

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

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

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

Error: -11

Fixed submission:

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

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

#include <iostream>
using namespace std;

int main() {
  int in[10], out[10];
  int in_num = 0;
  int out_num = 0;
  int n;
  while (cin >> n) {
    if (n == 0) {
      in_num--;
      out[out_num] = in[in_num];
      cout << out[out_num] << endl;
      out_num++;
    } else {
      in[in_num] = n;
      in_num++;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int in[10], out[10];
  int in_num = 0;
  int out_num = 0;
  int n;
  while (cin >> n) {
    if (n == 0) {
      in_num--;
      out[out_num] = in[in_num];
      out_num++;
    } else {
      in[in_num] = n;
      in_num++;
    }
  }
  for (int i = 0; i < out_num; i++)
    cout << out[i] << endl;

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

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

int main() {
  int a[100];
  int i = 0;
  while (cin >> a[i]) {
    if (a[i] == 0) {
      int j = i;
      while (1) {
        j--;
        if (a[j] != 0) {
          cout << a[j] << endl;
          a[j] = 0;
          break;
        }
      }
    }
    i++;
  }

  return 0;
}


Error: -11

Fixed submission:

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

int main() {
  int a[100];
  int i = 0;

  while (1) {
    cin >> a[i];
    if (a[i] == 0) {
      int j = i;
      while (1) {
        j--;
        if (a[j] != 0) {
          cout << a[j] << endl;
          a[j] = 0;
          break;
        }
      }
    }
    i++;
  }

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

#include <iostream>

using namespace std;

int main() {
  int track[10], c, num;
  while (1) {
    cin >> num;
    if (!num) {
      if (!c)
        break;
      else
        cout << track[c--] << endl;
    } else {
      if (c == 10)
        cout << "Already Full" << endl;
      else
        track[++c] = num;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int track[10], c, num;
  while (1) {
    cin >> num;
    if (!num) {
      if (!c)
        cout << "No train" << endl;
      else
        cout << track[c--] << endl;
    } else {
      if (c == 10)
        cout << "Already Full" << endl;
      else
        track[++c] = num;
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int train[200000] = {0}, junban[200000] = {0}, a = 0, n, i;
  while (cin >> n) {
    if (n == 0) {
      for (i = 0; train[i] != 0; i++) {
      }
      junban[a] = train[i - 1];
      train[i - 1] = 0;
      a++;
    } else {
      for (i = 0; train[i] != 0; i++) {
      }
      train[i] = n;
    }
  }
  for (i = 0; junban[i] > 0; i++) {
    cout << junban[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int train[11] = {0}, junban[11] = {0}, a = 0, n, i;
  while (cin >> n) {
    if (n == 0) {
      for (i = 0; train[i] != 0; i++) {
        i + 1;
      }
      junban[a] = train[i - 1];
      train[i - 1] = 0;
      a++;
    } else {
      for (i = 0; train[i] != 0; i++) {
        i + 1;
      }
      train[i] = n;
    }
  }
  for (i = 0; junban[i] > 0; i++) {
    cout << junban[i] << endl;
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

using namespace std;

int main() {
  int in[10];
  int i = 0;

  while (scanf("%d", &in[i]) != EOF) {
    if (in[i] == 0) {
      i--;
      printf("%d\\n", in[i]);
    } else {
      i++;
    }
  }
}

Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

int main() {
  int in[10];
  int i = 0;

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

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

int main() {
  int n, count = 0;
  stack<int> get;
  while (cin >> n) {
    if (n == 0) {
      cout << get.top() << endl;
      get.pop();
      count -= 1;
    } else {
      get.push(n);
      count += 1;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

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

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

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

int main() {
  int n;
  vector<int> g;
  while (cin >> n) {
    if (n != 0) {
      g.push_back(n);
    } else {
      n = g.back();
      g.pop_back();
      cout << n << endl;
    }
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

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

int main() {
  int n;
  vector<int> g;
  while (true) {
    cin >> n;
    if (n != 0) {
      g.push_back(n);
    } else {
      n = g.back();
      g.pop_back();
      cout << n << endl;
    }
  }
  return 0;
}
Problem p00013 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int in;
  vector<int> a;
  while (cin >> in) {
    if (in == 0) {
      cout << a.back();
      a.pop_back();
      /*if (a.size() == 0)
              break;
      else*/
      cout << endl;
    } else
      a.push_back(in);
  }
  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int in;
  vector<int> a;
  while (1) {
    cin >> in;
    if (in == 0) {
      cout << a[a.size() - 1];
      a.erase(a.end());
      if (a.size() == 0)
        break;
      else
        cout << endl;
    } else
      a.push_back(in);
  }
  return 0;
}