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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a, b;
  stack<int> st;
  string op;
  while (cin >> op) {
    // cout << op << endl;
    if (isdigit(op[0]))
      st.push(stoi(op));
    else {
      b = st.top();
      st.pop();
      a = st.top();
      st.pop();
      switch (op[0]) {
      case '+':
        st.push(a + b);
        break;
      case '-':
        st.push(a - b);
        break;
      case '*':
        st.push(a * b);
        break;
      }
    }
  }
  cout << st.top() << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a, b;
  stack<int> st;
  string op;
  while (cin >> op) {
    cin >> op;
    if (isdigit(op[0]))
      st.push(stoi(op));
    else {
      b = st.top();
      st.pop();
      a = st.top();
      st.pop();
      switch (op[0]) {
      case '+':
        st.push(a + b);
        break;
      case '-':
        st.push(a - b);
        break;
      case '*':
        st.push(a * b);
        break;
      }
    }
  }
  cout << st.top() << endl;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main() {
  stack<int> num;
  string s;
  int a, b;
  while (cin >> s) {
    if (s >= "0")
      num.push(atoi(s.c_str()));
    else if (s == "+" || s == "-" || s == "*") {
      a = num.top();
      num.pop();
      b = num.top();
      num.pop();
      if (s == "+")
        num.push(a + b);
      else if (s == "-")
        num.push(b - a);
      else
        num.push(a * b);
    }
  }
  cout << num.top() << endl;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main() {
  stack<int> num;
  string s;
  int a, b;
  while (cin >> s) {
    if (s >= "1")
      num.push(atoi(s.c_str()));
    else if (s == "+" || s == "-" || s == "*") {
      a = num.top();
      num.pop();
      b = num.top();
      num.pop();
      if (s == "+")
        num.push(a + b);
      else if (s == "-")
        num.push(b - a);
      else
        num.push(a * b);
    }
  }
  cout << num.top() << endl;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
bool is_digit(const string &str) {
  return str.length() > 0 && str[0] != '+' && str[0] != '-' && str[0] != '*';
}

inline int compute(const char oprt, int a, int b) {
  if (oprt == '+') {
    return a + b;
  } else if (oprt == '-') {
    return a - b;
  } else {
    return a * b;
  }
}

int main() {
  stack<int> operands;
  vector<string> inputs;
  string cur;
  while (cin >> cur) {
    inputs.push_back(cur);
  }

  for (int i = 0; i < (int)inputs.size(); ++i) {
    string cur = inputs[i];
    if (is_digit(cur)) {
      operands.push(atoi(cur.c_str()));
    } else {
      int operand_1 = operands.top();
      operands.pop();
      int operand_2 = operands.top();
      operands.pop();
      char oprt = cur[0];
      operands.push(compute(oprt, operand_2, operand_1));
    }
  }

  cout << operands.top() << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
bool is_digit(const string &str) {
  return str.length() > 0 && str[0] != '+' && str[0] != '-' && str[0] != '*';
}

inline int compute(const char oprt, int a, int b) {
  if (oprt == '+') {
    return a + b;
  } else if (oprt == '-') {
    return a - b;
  } else {
    return a * b;
  }
}
int main() {
  stack<int> operands;
  vector<string> inputs;
  string cur;
  while (!cin.eof()) {
    cin >> cur;
    inputs.push_back(cur);
  }

  for (int i = 0; i < (int)inputs.size(); ++i) {
    string cur = inputs[i];
    if (is_digit(cur)) {
      operands.push(atoi(cur.c_str()));
    } else {
      int operand_1 = operands.top();
      operands.pop();
      int operand_2 = operands.top();
      operands.pop();
      char oprt = cur[0];
      operands.push(compute(oprt, operand_2, operand_1));
    }
  }

  cout << operands.top() << endl;

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

#include <iostream>
#include <stack>

using namespace std;

int main() {
  stack<int> stack;

  string s;
  while (cin >> s) {
    if (s == "+" || s == "*" || s == "-") {
      int x = stack.top();
      stack.pop();
      int y = stack.top();
      stack.pop();

      if (s == "+") {
        stack.push(x + y);
      } else if (s == "-") {
        stack.push(y - x);
      } else {
        stack.push(x * y);
      }
    } else {
      int n = stoi(s);
      stack.push(n);
    }
  }
  int r = stack.top();
  cout << r << endl;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stack>

using namespace std;

int main() {
  stack<int> stack;

  string s;
  while (cin >> s) {
    if (s == "+" || s == "*") {
      int x = stack.top();
      stack.pop();
      int y = stack.top();
      stack.pop();

      if (s == "+") {
        stack.push(x + y);
      } else {
        stack.push(x * y);
      }
    } else {
      int n = stoi(s);
      stack.push(n);
    }
  }
  int r = stack.top();
  cout << r << endl;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <stdlib.h>

#define MAX 1000

void initialize();
int isEmpty();
int isFull();
void push(int x);
int pop();

int top;
int S[1000];

int main() {
  int i, n, ans, n1, n2, n3;
  char c[100];

  initialize();

  while (1) {
    if (scanf("%s", c) == EOF)
      break;

    if (c[0] == '+' || c[0] == '-' || c[0] == '*') {
      n1 = pop();
      n2 = pop();
      if (c[0] == '+')
        n3 = n1 + n2;
      if (c[0] == '-')
        n3 = n2 - n1;
      if (c[0] == '*')
        n3 = n1 * n2;
      push(n3);
    } else {
      n = atoi(c);
      push(n);
    }
  }

  printf("%d\\n", pop());
  return 0;
}

void initialize() { top = 0; }

int isEmpty() { return top == 0; }

int isFull() { return top >= MAX - 1; }

void push(int x) {
  if (isFull())
    fprintf(stderr, "overflow\\n");
  top++;
  S[top] = x;
}

int pop() {
  if (isEmpty())
    fprintf(stderr, "underflow\\n");
  top--;
  return S[top + 1];
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <stdlib.h>

#define MAX 1000

void initialize();
int isEmpty();
int isFull();
void push(int x);
int pop();

int top;
int S[100];

int main() {
  int i, n, ans, n1, n2, n3;
  char c[100];

  initialize();

  while (1) {
    if (scanf("%s", c) == EOF)
      break;

    if (c[0] == '+' || c[0] == '-' || c[0] == '*') {
      n1 = pop();
      n2 = pop();
      if (c[0] == '+')
        n3 = n1 + n2;
      if (c[0] == '-')
        n3 = n2 - n1;
      if (c[0] == '*')
        n3 = n1 * n2;
      push(n3);
    } else {
      n = atoi(c);
      push(n);
    }
  }

  printf("%d\\n", pop());
  return 0;
}

void initialize() { top = 0; }

int isEmpty() { return top == 0; }

int isFull() { return top >= MAX - 1; }

void push(int x) {
  if (isFull())
    fprintf(stderr, "overflow\\n");
  top++;
  S[top] = x;
}

int pop() {
  if (isEmpty())
    fprintf(stderr, "underflow\\n");
  top--;
  return S[top + 1];
}
Problem p02263 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdlib>
#include <iostream>
#include <stack>

using namespace std;

char expr[10000];

int main() {
  stack<long> S;
  cin.getline(expr, 10000);
  char *s = expr;
  for (;;) {
    if (*s == '\\0') {
      break;
    }
    if ('0' <= *s && *s <= '9') {
      S.push(strtol(s, &s, 10));
      if (*s == ' ') {
        ++s;
      }
    } else {
      long b = S.top();
      S.pop();
      long a = S.top();
      S.pop();
      long r = 0;
      switch (*s) {
      case '+':
        r = a + b;
        break;
      case '-':
        r = a - b;
        break;
      case '*':
        r = a * b;
        break;
      }
      ++s;
      if (*s == ' ') {
        ++s;
      }
      S.push(r);
    }
  }
  cout << S.top() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
using namespace std;
int n;
char A[100][8];
int S[100];
int s = 0;
int main() {
  while (cin.peek() != 14) {
    cin >> A[n++];
  }

  for (int i = 0; i < n; i++) {
    switch (A[i][0]) {
    case '+':
      S[s - 1] += S[--s];
      break;
    case '-':
      S[s - 1] -= S[--s];
      break;
    case '*':
      S[s - 1] *= S[--s];
      break;
    default:
      S[s++] = atoi(A[i]);
    }
  }

  cout << S[0] << endl;

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

#include <cassert>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x) { S[++top] = x; }

int pop() {
  top--;
  return S[top + 1];
}

int main() {
  int a, b, x, no, np;
  top = 0;
  char s[100];
  no = np = 0;
  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
      no++;
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
      no++;
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
      no++;
    } else {
      x = atoi(s);
      assert(0 <= x && x <= 1000000);
      push(x);
      np++;
    }
  }
  assert(2 <= np && np <= 100);
  assert(1 <= no && no <= 99);

  printf("%d\\n", pop());

  return 0;
}

Error: 0

Fixed submission:

#include <cassert>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x) { S[++top] = x; }

int pop() {
  top--;
  return S[top + 1];
}

int main() {
  int a, b, x, no, np;
  top = 0;
  char s[100];
  no = np = 0;
  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
      no++;
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
      no++;
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
      no++;
    } else {
      x = atoi(s);
      assert(0 <= x && x <= 1000000);
      push(x);
      np++;
    }
  }
  assert(2 <= np && np <= 100);
  assert(1 <= no && no <= 9);

  printf("%d\\n", pop());

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

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <vector>

class Stack {
public:
  Stack() : top(0){};

  void push(int a) {
    v.push_back(a);
    top++;
  };
  int pop() {
    int a = v[--top];
    v.pop_back();
    return (a);
  };

private:
  int top;
  std::vector<int> v;
};
/*
void culcurate(Stack S, char* operata){
    if(strcmp(operata, "+")){
        int a = S.pop();
        int b = S.pop();
        S.push(a + b);
    }else if(strcmp(operata, "-")){
        int a = S.pop();
        int b = S.pop();
        S.push(a - b);
    }else if(strcmp(operata, "*")){
        int a = S.pop();
        int b = S.pop();
        S.push(a * b);
    }
}
*/
int main() {
  Stack S = Stack();
  char buf[100];
  while (scanf("%s", buf) != EOF) {
    if (buf[0] == '+') {
      int a = S.pop();
      int b = S.pop();
      S.push(b + a);
    } else if (buf[0] == '-') {
      int a = S.pop();
      int b = S.pop();
      S.push(b - a);
    } else if (buf[0] == '*') {
      int a = S.pop();
      int b = S.pop();
      S.push(b * a);
    } else {
      int a = std::atoi(buf);
      S.push(a);
    }
  }

  printf("%d\\n", S.pop());
  return 0;
}


Error: -11

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <vector>

class Stack {
public:
  Stack() : top(0){};

  void push(int a) {
    v.push_back(a);
    top++;
  };
  int pop() {
    int a = v[--top];
    v.pop_back();
    return (a);
  };

private:
  int top;
  std::vector<int> v;
};
/*
void culcurate(Stack S, char* operata){
    if(strcmp(operata, "+")){
        int a = S.pop();
        int b = S.pop();
        S.push(a + b);
    }else if(strcmp(operata, "-")){
        int a = S.pop();
        int b = S.pop();
        S.push(a - b);
    }else if(strcmp(operata, "*")){
        int a = S.pop();
        int b = S.pop();
        S.push(a * b);
    }
}
*/
int main() {
  Stack S = Stack();
  char buf[100];
  while (!std::cin.eof()) {
    if (buf[0] == '+') {
      int a = S.pop();
      int b = S.pop();
      S.push(a + b);
    } else if (buf[0] == '-') {
      int a = S.pop();
      int b = S.pop();
      S.push(a - b);
    } else if (buf[0] == '*') {
      int a = S.pop();
      int b = S.pop();
      S.push(a * b);
    } else {
      int a = std::atoi(buf);
      S.push(a);
    }
    scanf("%s", buf);
  }

  printf("%d\\n", S.pop());
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

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

int num[100], top;

int pop();
void push(int x);

int main() {
  int a, b;
  top = 0;
  string s;
  getline(cin, s);

  for (int j = 0; s[j] != '\\0'; j++) {
    if (s[j] == ' ')
      continue;
    else if (s[j] != '+' && s[j] != '-' && s[j] != '*') {
      int l = 0;
      num[top] = 0;
      while (s[j] != ' ') {
        l++;
        j++;
      }
      num[top] += atoi(&s[j - l]);
      top++;
    } else {
      a = pop();
      b = pop();
      if (s[j] == '+')
        push(b + a);
      else if (s[j] == '-')
        push(b - a);
      else if (s[j] == '*')
        push(a * b);
      top++;
    }
  }
  cout << num[0] << endl;
  return 0;
}

int pop() {
  top--;
  return num[top];
}

void push(int x) { num[top] = x; }

Error: -11

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int num[100], top, i;

int pop();
void push(int x);

int main() {
  int a, b, sum = 0;
  top = 0;
  i = 0;
  char s[100];

  scanf("%c", s);

  while (top != 1 || sum != 2) {
    if (s[sum] != '+' && s[sum] != '-' && s[sum] != '*') {
      num[i] = atoi(&s[sum]);
      i++;
      sum++;
    } else {
      a = pop();
      b = pop();
      if (s[sum] == '+')
        push(b + a);
      else if (s[sum] == '-')
        push(b - a);
      else if (s[sum] == '*')
        push(a * b);
      i++;
    }
  }
  cout << num[top - 1] << endl;
  return 0;
}

int pop() {
  i--;
  return num[i];
}

void push(int x) { num[top++] = x; }
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
using namespace std;
int main() {
  string str;
  stack<int> st;
  getline(cin, str);
  stringstream ss(str);
  while (ss >> str) {
    if (isdigit(str[0])) {
      int x = atoi(str.c_str());
      st.push(x);
    } else {
      int p2 = st.top();
      st.pop();
      int p1 = st.top();
      st.pop();
      switch (str[0]) {
      case '+':
        st.push(p1 + p2);
        break;
      case '-':
        st.push(p1 - p2);
        break;
      case '*':
        st.push(p1 * p2);
        break;
      }
    }
  }
  cout << st.top() << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
using namespace std;
int main() {
  string str;
  stack<int> st;
  while (!cin.eof()) {
    cin >> str;
    if (isdigit(str[0])) {
      int x = atoi(str.c_str());
      st.push(x);
    } else {
      int p1 = st.top();
      st.pop();
      int p2 = st.top();
      st.pop();
      switch (str[0]) {
      case '+':
        st.push(p1 + p2);
        break;
      case '-':
        st.push(p1 - p2);
        break;
      case '*':
        st.push(p1 * p2);
        break;
      }
    }
  }
  cout << st.top() << endl;

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

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

int main() {
  stack<int> a;
  string data;
  int ans, b, c;
  stringstream ss;
  while (cin >> data) {
    if (data == "*") {
      b = a.top();
      a.pop();
      c = a.top();
      a.pop();
      ans = c * b;
    } else if (data == "+") {
      b = a.top();
      a.pop();
      c = a.top();
      a.pop();
      ans = c + b;
    } else if (data == "-") {
      b = a.top();
      a.pop();
      c = a.top();
      a.pop();
      ans = c - b;
    } else {
      ss << data;
      ss >> ans;
      ss.str("");
      ss.clear(stringstream::goodbit);
    }
    a.push(ans);
  }
  cout << a.top() << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  stack<int> a;
  string data;
  int ans, b, c;
  stringstream ss;
  cin >> data;
  while (data != "\\0") {
    if (data == "*") {
      b = a.top();
      a.pop();
      ;
      c = a.top();
      a.pop();
      ans = c * b;
    } else if (data == "+") {
      b = a.top();
      a.pop();
      c = a.top();
      a.pop();
      ans = c + b;
    } else if (data == "-") {
      b = a.top();
      a.pop();
      c = a.top();
      a.pop();
      ans = c - b;
    } else {
      ss << data;
      ss >> ans;
      ss.str("");
      ss.clear(stringstream::goodbit);
    }
    a.push(ans);
    cin >> data;
  }
  cout << a.top() << endl;
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

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

int cul(int n1, int n2, string ss) {
  int ret;
  if (ss == "+")
    ret = n1 + n2;
  if (ss == "-")
    ret = n1 - n2;
  if (ss == "*")
    ret = n1 * n2;
  return ret;
}

int main() {
  stack<int> s;
  string st;
  int m1, m2;
  while (cin >> st) {
    if (st == "+" || st == "-" || st == "*") {
      m2 = s.top();
      s.pop();
      m1 = s.top();
      s.pop();
      s.push(cul(m1, m2, st));
    } else {
      s.push(atoi(st.c_str()));
    }
  }
  cout << s.top() << endl;
}

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


Fixed submission:

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

int cul(int n1, int n2, int n0) {
  int ret;
  if (n0 == '+')
    ret = n1 + n2;
  if (n0 == '-')
    ret = n1 - n2;
  if (n0 == '*')
    ret = n1 * n2;
  return ret;
}

int main() {
  stack<int> s;
  int m0, m1, m2;
  while (cin >> m0) {
    while (1) {
      if (m0 == '+' || m0 == '-' || m0 == '*') {
        m2 = s.top();
        s.pop();
        m1 = s.top();
        s.pop();
        s.push(cul(m1, m2, m0));
        break;
      } else {
        s.push(m0);
        cin >> m0;
      }
    }
  }
  cout << s.top() << endl;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <stdio.h>
#include <string>
using namespace std;

#define abs(N) ((N > 0) ? N : -1 * N)
#define lt(A, B) ((A > B) ? B : A)
#define gt(A, B) ((A < B) ? B : A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

template <typename T> class stack {
public:
  const static int MAX = 10000;
  stack<T>() { pos = 0; }

  void empty() { pos = 0; }

  bool isEmpty() { return (pos == 0); }

  bool isFull() { return (pos == MAX); }

  T pop() {
    if (isEmpty()) {
      throw exception();
    }
    return body[--pos];
  }

  void push(T el) {
    if (isFull()) {
      throw exception();
    }
    body[pos++] = el;
  }

  T top() {
    if (isEmpty()) {
      throw exception();
    }
    return body[pos - 1];
  }

private:
  T body[MAX];
  int pos;
};

int main() {
  string buf, str;
  char cstr[1000];
  cin.getline(cstr, sizeof(cstr));
  str = string(cstr);
  stringstream ss(str);
  stack<int> st;
  while (getline(ss, buf, ' ')) {
    //		println("-----"+buf+"-----");
    if (buf == "+" || buf == "-" || buf == "*") {
      int r1, r2, ret;
      r1 = st.pop();
      r2 = st.pop();
      if (buf == "+") {
        ret = r1 + r2;
      }
      if (buf == "-") {
        ret = r2 - r1;
      }
      if (buf == "*") {
        ret = r1 * r2;
      }
      st.push(ret);
    } else {
      st.push(atoi(buf.c_str()));
    }
  }
  println(st.top());

  return 0;
}


Error: 0

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <stdio.h>
#include <string>
using namespace std;

#define abs(N) ((N > 0) ? N : -1 * N)
#define lt(A, B) ((A > B) ? B : A)
#define gt(A, B) ((A < B) ? B : A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

template <typename T> class stack {
public:
  const static int MAX = 3;
  stack<T>() { pos = 0; }

  void empty() { pos = 0; }

  bool isEmpty() { return (pos == 0); }

  bool isFull() { return (pos == MAX); }

  T pop() {
    if (isEmpty()) {
      throw exception();
    }
    return body[--pos];
  }

  void push(T el) {
    if (isFull()) {
      throw exception();
    }
    body[pos++] = el;
  }

  T top() {
    if (isEmpty()) {
      throw exception();
    }
    return body[pos - 1];
  }

private:
  T body[MAX];
  int pos;
};

int main() {
  string buf, str;
  char cstr[1000];
  cin.getline(cstr, sizeof(cstr));
  str = string(cstr);
  stringstream ss(str);
  stack<int> st;
  while (getline(ss, buf, ' ')) {
    //		println("-----"+buf+"-----");
    if (buf == "+" || buf == "-" || buf == "*") {
      int r1, r2, ret;
      r1 = st.pop();
      r2 = st.pop();
      if (buf == "+") {
        ret = r1 + r2;
      }
      if (buf == "-") {
        ret = r2 - r1;
      }
      if (buf == "*") {
        ret = r1 * r2;
      }
      st.push(ret);
    } else {
      st.push(atoi(buf.c_str()));
    }
  }
  println(st.top());

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

#include <algorithm>
#include <cctype>
#include <iostream>
#include <list>
#include <sstream>
#include <string>
using namespace std;

int main(int argc, char **argv) {

  list<int> l;
  l.push_back(0);
  list<int>::iterator top = l.begin();

  string expr;
  getline(cin, expr);
  istringstream is(expr);
  int x, y;
  while (!is.eof()) {
    string op;
    is >> op;
    switch (op[0]) {
    case '+':
      y = *top;
      top--;
      l.pop_back();
      x = *top;
      top--;
      l.pop_back();
      l.push_back(x + y);
      top++;
      break;
    case '-':
      y = *top;
      top--;
      l.pop_back();
      x = *top;
      top--;
      l.pop_back();
      l.push_back(x - y);
      top++;
      break;
    case '*':
      y = *top;
      top--;
      l.pop_back();
      x = *top;
      top--;
      l.pop_back();
      l.push_back(x * y);
      top++;
      break;
    default:
      istringstream is2(op);
      is2 >> x;
      l.push_back(x);
      top++;
      break;
    }
  }
  cout << *top << endl;
  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <ctype.h>
#include <iostream>
#include <list>
using namespace std;

int main(int argc, char **argv) {

  list<int> l;
  l.push_back(0);
  list<int>::iterator top = l.begin();

  char a;
  int x, y;
  for (int i = 0; i < 200; i++) {
    cin >> a;
    if (isdigit(a)) {
      x = static_cast<int>(a);
      l.push_back(a);
      top++;
    } else {
      switch (a) {
      case '+':
        y = *top;
        top--;
        l.pop_back();
        x = *top;
        top--;
        l.pop_back();
        l.push_back(x + y);
        top++;
        break;
      case '-':
        y = *top;
        top--;
        l.pop_back();
        x = *top;
        top--;
        l.pop_back();
        l.push_back(x - y);
        top++;
        break;
      case '*':
        y = *top;
        top--;
        l.pop_back();
        x = *top;
        top--;
        l.pop_back();
        l.push_back(x * y);
        top++;
        break;
      }
    }
  }
  cout << *top << endl;
  return 0;
}