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

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

int main(void) {
  stack<int> s;
  string p;
  while (cin >> p) {
    if (p == "+") {
      int b = s.top();
      s.pop();
      int a = s.top();
      s.pop();
      s.push(a + b);
    } else if (p == "-") {
      int b = s.top();
      s.pop();
      int a = s.top();
      s.pop();
      s.push(a - b);
    } else if (p == "*") {
      int b = s.top();
      s.pop();
      int a = s.top();
      s.pop();
      s.push(a * b);
    } else {
      s.push(stoi(p));
    }
  }
  cout << s.top() << endl;

  return 0;
}


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


Fixed submission:

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

int main(void) {
  stack<int> s;
  while (!cin.eof()) {
    string p;
    cin >> p;
    if (p == "+") {
      int b = s.top();
      s.pop();
      int a = s.top();
      s.pop();
      s.push(a + b);
    } else if (p == "-") {
      int b = s.top();
      s.pop();
      int a = s.top();
      s.pop();
      s.push(a - b);
    } else if (p == "*") {
      int b = s.top();
      s.pop();
      int a = s.top();
      s.pop();
      s.push(a * b);
    } else {
      s.push(stoi(p));
    }
  }
  cout << s.top() << endl;

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

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int S[200];
int top = 0;

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

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

int main() {
  string s;
  char c;
  int a, b;
  // cin >> s;
  // getline(cin, s);
  // int i=0;
  // cout << s << endl;

  // for (char& c: s) {
  // cout << "c: "<< c << endl;
  // while(c = s[i]){
  while (cin >> s) {
    // cout << "s: " << s << endl;
    if (s == "+") {
      a = pop();
      b = pop();
      push(a + b);
      // cout << "\\t" << a+b << " push " << endl;
    } else if (s == "-") {
      a = pop();
      b = pop();
      // cout << "\\t" << a-b << " push " << ", a: "<< a << ", b: "<< b << endl;
      push(b - a);
    } else if (s == "*") {
      a = pop();
      b = pop();
      push(a * b);
      // cout << "\\t" << a*b << " push " << endl;
    } else {
      int numA = 0;
      numA = 0;
      for (int i = 0; i < (int)s.size(); i++) {
        numA *= 10;
        numA += s[i] - '0';
      }
      push(numA);
      // cout << "\\t" << numA << " push " << endl;
    }
  }
  cout << pop() << endl;
  ;
  return 0;
}


Error: TLE

Fixed submission:

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

int S[200];
int top = 0;

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

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

int main() {
  string s;
  char c;
  int a, b;
  cin >> s;
  int i = 0;
  while (c = s[i]) {
    if (c == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (c == '-') {
      a = pop();
      b = pop();
      push(a - b);
    } else if (c == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else if (c == ' ') {
      continue;
    } else {
      push(c - '0');
    }
  }
  cout << pop() << endl;
  ;
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <stack>
using namespace std;
int main() {
  stack<int> S;
  int a, b;
  char s[1000];
  for (; scanf("%s", s) != EOF;) {
    if (s[0] == '+') {
      b = S.top();
      S.pop();
      a = S.top();
      S.pop();
      S.push(a + b);
    } else if (s[0] == '-') {
      b = S.top();
      S.pop();
      a = S.top();
      S.pop();
      S.push(a - b);
    } else if (s[0] == '*') {
      b = S.top();
      S.pop();
      a = S.top();
      S.pop();
      S.push(a * b);
    } else {
      S.push(atoi(s));
    }
  }
  printf("%d\\n", S.top());
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <stack>
using namespace std;
int main() {
  stack<int> S;
  int a, b;
  char s;
  for (; scanf("%s", &s) != EOF;) {
    if (s == '+') {
      b = S.top();
      S.pop();
      a = S.top();
      S.pop();
      S.push(a + b);
    } else if (s == '-') {
      b = S.top();
      S.pop();
      a = S.top();
      S.pop();
      S.push(a - b);
    } else if (s == '*') {
      b = S.top();
      S.pop();
      a = S.top();
      S.pop();
      S.push(a * b);
    } else {
      S.push(atoi(&s));
    }
  }
  printf("%d\\n", S.top());
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

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

stack<int> sta;

int main() {
  char n[11111];

  while (scanf(" %s", n) != EOF) {

    if (n[0] == '+') {
      int a = sta.top();
      sta.pop();
      int b = sta.top();
      sta.pop();
      a = a + b;
      sta.push(a);
    } else if (n[0] == '-') {
      int b = sta.top();
      sta.pop();
      int a = sta.top();
      sta.pop();
      a = a - b;
      sta.push(a);
    } else if (n[0] == '*') {
      int a = sta.top();
      sta.pop();
      int b = sta.top();
      sta.pop();
      a = a * b;
      sta.push(a);
    } else {
      sta.push(atoi(n));
    }

    // cout << sta.top() << endl;
  }

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

  return 0;
}

Error: -11

Fixed submission:

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

stack<int> sta;

int main() {
  string n;

  while (1) {

    cin >> n;

    if (n.back() == EOF)
      break;

    if (n[0] == '+') {
      int a = sta.top();
      sta.pop();
      int b = sta.top();
      sta.pop();
      a = a + b;
      sta.push(a);
    } else if (n[0] == '-') {
      int a = sta.top();
      sta.pop();
      int b = sta.top();
      sta.pop();
      a = a - b;
      sta.push(a);
    } else if (n[0] == '*') {
      int a = sta.top();
      sta.pop();
      int b = sta.top();
      sta.pop();
      a = a * b;
      sta.push(a);
    } else if (n[0] == '/') {
      int a = sta.top();
      sta.pop();
      int b = sta.top();
      sta.pop();
      a = a / b;
      sta.push(a);
    } else {
      int s = 1;
      int t = 0;
      while (!n.empty()) {
        t += (int)n.back() * s;
        n.pop_back();
        s *= 10;
      }
      sta.push(t);
    }

    cout << sta.top() << endl;
  }

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

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

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

class Stack {
private:
  int sp;
  int S[100];

public:
  Stack() { sp = 0; }
  bool isFull() const { return (sp == 100); }
  bool isEmpty() const { return (sp == 0); }
  void push(int d);
  int top();
  void pop();
};

void Stack::push(int d) {
  if (isFull())
    return;
  S[sp++] = d;
}

int Stack::top() {
  if (isEmpty())
    return -1;

  return S[sp - 1];
}

void Stack::pop() {
  if (isEmpty())
    return;

  sp--;
}

int main() {

  Stack s;

  string expr;
  getline(cin, expr);

  istringstream is(expr);

  while (!is.eof()) {
    string op;
    is >> op;

    int tmp1, tmp2;

    switch (op[0]) {
    case '+':
      tmp1 = s.top();
      s.pop();
      tmp2 = s.top();
      s.pop();
      s.push(tmp2 + tmp1);
      break;

    case '-':
      tmp1 = s.top();
      s.pop();
      tmp2 = s.top();
      s.pop();
      s.push(tmp2 - tmp1);
      break;

    case '*':
      tmp1 = s.top();
      s.pop();
      tmp2 = s.top();
      s.pop();
      s.push(tmp2 * tmp1);
      break;

    default:
      istringstream is2(op);
      is2 >> tmp1;
      s.push(tmp1);
      break;
    }
  }

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

  return 0;
}

Error: -11

Fixed submission:

#include <cctype>
#include <cstdlib>
#include <iostream>
using namespace std;

class Stack {
private:
  unsigned size;
  int *data;
  int *t;

public:
  Stack(unsigned s) {
    size = s;
    data = new int[size + 1];
    t = data;
  }
  void push(int a) {
    ++t;
    *t = a;
  }
  void pop() { --t; }
  int top() { return *t; }
  bool isFull() {
    if (t == data + size) {
      return true;
    } else {
      return false;
    }
  }
  bool isEmpty() {
    if (t == data) {
      return true;
    } else {
      return false;
    }
  }
};

int main() {
  Stack s(5);
  char P[10];

  while (1) {
    cin >> P;
    if (!isdigit(P[0]) == 0) {
      int m = atoi(P);
      s.push(m);
    } else {
      if (P[0] == '+') {
        int x, y;
        x = s.top();
        s.pop();
        y = s.top();
        s.pop();
        int tmp = x + y;
        s.push(tmp);
      }
      if (P[0] == '-') {
        int x, y;
        x = s.top();
        s.pop();
        y = s.top();
        s.pop();
        int tmp = y - x;
        s.push(tmp);
      }
      if (P[0] == '*') {
        int x, y;
        x = s.top();
        s.pop();
        y = s.top();
        s.pop();
        int tmp = x * y;
        s.push(tmp);
      }
      if (P[0] == '/') {
        int x, y;
        x = s.top();
        s.pop();
        y = s.top();
        s.pop();
        int tmp = y / x;
        s.push(tmp);
      }
    }
    if (P[0] == 'F') {
      cout << s.top() << endl;
      break;
    }
  }
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

/*
???????????????????¨??????§??????????????°??????????????????
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
const int LEN = 101; //???????????§??????

class stack {
  int data[LEN];
  int top;

public:
  stack() : top(0){};
  void push(int);
  int pop();
  bool isEmpty();
  bool isFull();
  int get_top() { return top; }
};
void stack::push(int num) {
  if (isFull())
    return;

  data[top + 1] = num;
  top++;
}
int stack::pop() {
  if (isEmpty())
    return 0;

  top--;
  return data[top + 1];
}
bool stack::isEmpty() { return top == 0; }
bool stack::isFull() { return top == LEN - 1; }

int main() {

  stack s;

  char oper[110];

  int a, b;

  while (scanf("%s", &oper) != EOF) {

    switch (oper[0]) {
    case '+':
      a = s.pop();
      b = s.pop();
      s.push(b + a);
      break;

    case '-':
      a = s.pop();
      b = s.pop();
      s.push(b - a);
      break;

    case '*':
      a = s.pop();
      b = s.pop();
      s.push(b * a);
      break;

    default:
      s.push(atoi(oper));
    }
  }

  cout << s.pop() << endl;
}


Error: 0

Fixed submission:

/*
???????????????????¨??????§??????????????°??????????????????
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
const int LEN = 100; //???????????§??????

class stack {
  int data[LEN];
  int top;

public:
  stack() : top(0){};
  void push(int);
  int pop();
  bool isEmpty();
  bool isFull();
  int get_top() { return top; }
};
void stack::push(int num) {
  if (isFull())
    return;

  data[top + 1] = num;
  top++;
}
int stack::pop() {
  if (isEmpty())
    return 0;

  top--;
  return data[top + 1];
}
bool stack::isEmpty() { return top == 0; }
bool stack::isFull() { return top == LEN - 1; }

int main() {

  stack s;

  char oper[11];

  int a, b;

  while (scanf("%s", &oper) != EOF) {

    switch (oper[0]) {
    case '+':
      if (s.get_top() < 2)
        exit(1);
      a = s.pop();
      b = s.pop();
      s.push(b + a);
      break;

    case '-':
      if (s.get_top() < 2)
        exit(1);
      a = s.pop();
      b = s.pop();
      s.push(b - a);
      break;

    case '*':
      if (s.get_top() < 2)
        exit(1);
      a = s.pop();
      b = s.pop();
      s.push(b * a);
      break;

    default:
      s.push(atoi(oper));
    }
  }

  cout << s.pop() << endl;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

template <typename T, int N> class stack {
private:
  int size;
  T array[N];

public:
  stack() { size = 0; }

  bool push(T x) {
    if (isFull()) {
      return false;
    }
    array[size] = x;
    size++;

    return true;
  }

  T pop() {
    size--;
    return array[size];
  }

  bool isEmpty() {
    if (size == 0) {
      return true;
    } else {
      return false;
    }
  }

  bool isFull() {
    if (size >= N) {
      return true;
    } else {
      return false;
    }
  }
};

int main() {
  stack<int, 20000> st;
  string a;
  while (cin >> a) {
    if (a[0] == '+') {
      int a = st.pop();
      int b = st.pop();
      st.push(b + a);
    } else if (a[0] == '-') {
      int a = st.pop();
      int b = st.pop();
      st.push(b - a);
    } else if (a[0] == '*') {
      int a = st.pop();
      int b = st.pop();
      st.push(b * a);
    } else {
      int x = 0;
      for (int i = 0; i < a.size(); i++) {
        x *= 10;
        x += a[i] - '0';
      }
      st.push(x);
    }
  }
  cout << st.pop() << "\\n";
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

template <typename T, int N> class stack {
private:
  int size;
  T array[N];

public:
  stack() { size = 0; }

  bool push(T x) {
    if (isFull()) {
      return false;
    }
    array[size] = x;
    size++;

    return true;
  }

  T pop() {
    size--;
    return array[size];
  }

  bool isEmpty() {
    if (size == 0) {
      return true;
    } else {
      return false;
    }
  }

  bool isFull() {
    if (size >= N) {
      return true;
    } else {
      return false;
    }
  }
};

int main() {
  stack<int, 20000> st;
  string a;
  int j = 0;
  while (j < 7) {
    j++;
    cin >> a;
    if (a[0] == '+') {
      int a = st.pop();
      int b = st.pop();
      st.push(b + a);
    } else if (a[0] == '-') {
      int a = st.pop();
      int b = st.pop();
      st.push(b - a);
    } else if (a[0] == '*') {
      int a = st.pop();
      int b = st.pop();
      st.push(b * a);
    } else {
      int x = 0;
      for (int i = 0; i < a.size(); i++) {
        x *= 10;
        x += a[i] - '0';
      }
      st.push(x);
    }
  }
  cout << st.pop() << "\\n";
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

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

struct stack {
public:
  int top;
  int stk[10000];

  void reset() { top = 0; }
  void push(int x) {
    top++;
    stk[top] = x;
  }
  int pop() {
    top--;
    return stk[top + 1];
  }
};

int main() {
  string in;
  stack stack;
  stack.reset();
  while (true) {
    cin >> in;
    if (cin.eof())
      break;
    else if (in == "+") {
      int a = stack.pop();
      int b = stack.pop();
      stack.push(a + b);
    } else if (in == "*") {
      int a = stack.pop();
      int b = stack.pop();
      stack.push(a * b);
    } else if (in == "-") {
      int a = stack.pop();
      int b = stack.pop();
      stack.push(b - a);
    } else {
      stack.push(atoi(in.c_str()));
    }
  }
  cout << stack.pop() << endl;
}


Error: 0

Fixed submission:

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

struct stack {
public:
  int top;
  int stk[5];

  void reset() { top = 0; }
  void push(int x) {
    top++;
    stk[top] = x;
  }
  int pop() {
    top--;
    return stk[top + 1];
  }
};

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

#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

class stack {
public:
  int s[100];
  int t;

public:
  void initialize();
  void push(int x);
  int pop();
};

void stack::initialize() { t = 0; }

void stack::push(int x) {
  s[t] = x;
  t++;
}

int stack::pop() {
  t--;
  return s[t];
}

int main() {
  stack st;
  string ch;
  int a, b;

  st.initialize();

  while (cin >> ch) {
    if (ch == "+") {
      a = st.pop();

      b = st.pop();

      st.push(a + b);

    } else if (ch == "-") {
      a = st.pop();

      b = st.pop();

      st.push(b - a);
    } else if (ch == "*") {
      a = st.pop();

      b = st.pop();

      st.push(a * b);
    } else {
      st.push(atoi(ch.c_str()));
    }
  }

  cout << st.s[0] << "\\n";

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

class stack {
public:
  string symbol;
  int t;

public:
  void initialize();
  void push(int x);
  char pop();
  char top();
};

void stack::initialize() { t = 0; }

void stack::push(int x) {
  symbol[t] = x;
  t++;
}

char stack::pop() {
  t--;
  return symbol[t];
}

char stack::top() { return symbol[t]; }

int main() {
  stack s;
  int a, b;

  while (cin >> s.symbol) {
    if (s.symbol == "+") {
      a = s.top();
      b = s.pop();
      s.push(a + b);
    }
    if (s.symbol == "-") {
      a = s.top();
      b = s.pop();
      s.push(b - a);
    }
    if (s.symbol == "*") {
      a = s.top();
      b = s.pop();
      s.push(a * b);
    }
  }

  cout << s.top() << "\\n";

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

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

int main() {
  int ans[1000], i = 0;
  char ch[1000];
  while (1) {
    if (scanf("%s", ch) == EOF)
      break;

    if (ch[0] != '+' && ch[0] != '-' && ch[0] != '*')
      ans[i] = atoi(ch);
    else {
      if (ch[0] == '+')
        ans[i - 2] += ans[i - 1];
      else if (ch[0] == '-')
        ans[i - 2] -= ans[i - 1];
      else if (ch[0] == '*')
        ans[i - 2] *= ans[i - 1];
      i -= 2;
    }
    i++;
  }
  cout << ans[0] << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int f = 0, f1 = 0, a;
  string str;
  int count = 0, count1 = 0;
  while (1) {
    cin >> str;
    if (str == ".")
      break;
  }
  a = str.size();
  for (int i = 0; i < a - 1; i++)
    if (str[i] == '[')
      count++;
    else if (str[i] == '{')
      count1++;
    else if (str[i] == '}')
      count1--;
    else if (str[i] == ']')
      count--;

  if (count == 0 && count1 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

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

#include <algorithm>
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int solve(string s) {
  stack<int> stk;
  string n = "";
  int n1, n2;
  bool o = true;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+' || s[i] == '-' || s[i] == '*') {
      o = false;
      n2 = stk.top();
      stk.pop();
      n1 = stk.top();
      stk.pop();
      if (s[i] == '+')
        stk.push(n1 + n2);
      if (s[i] == '-')
        stk.push(n1 - n2);
      if (s[i] == '*')
        stk.push(n1 * n2);
    } else if (s[i] == ' ') {
      if (o)
        stk.push(stoi(n));
      o = true;
      n = "";
    } else
      n += s[i];
  }
  return stk.top();
}

int main() {
  string s;
  getline(cin, s);
  cout << solve(s) << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int solve(string s) {
  string a = "", n1 = "", n2 = "";
  int c = 0, num1, num2;
  bool ok = true;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == ' ') {
      c++;
      if (c == 1)
        num1 = stoi(n1);
      if (c == 2)
        num2 = stoi(n2);
      if (c == 3) {
        n1 = "";
        n2 = "";
        c = 0;
      }
    } else if (s[i] == '+') {
      ok = false;
      if (c == 2) {
        a += to_string(num1 + num2);
        a += " ";
      } else
        a += "+ ";
    } else if (s[i] == '-') {
      if (c == 2 && s[i + 1] == ' ') {
        ok = false;
        a += to_string(num1 - num2);
        a += " ";
      } else if (c == 0 && s[i + 1] != ' ')
        n1 += "-";
      else if (c == 1 && s[i + 1] != ' ')
        n2 += "-";
      else {
        ok = false;
        a += "- ";
      }
    } else if (s[i] == '*') {
      ok = false;
      if (c == 2) {
        a += to_string(num1 * num2);
        a += " ";
      } else
        a += "* ";
    } else {
      if (c == 0)
        n1 += s[i];
      if (c == 1)
        n2 += s[i];
    }
  }
  if (ok)
    return stoi(s);
  else
    return solve(a);
}

int main() {
  string s;
  getline(cin, s);
  cout << solve(s) << '\\n';
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string>

using namespace std;

int main(void) {
  string str;
  int x = 0, y = 0;
  stack<int> data;

  while (cin >> str) {
    if (str[0] == '\\n') {
      break;
    }
    if (str[0] == '+') {
      x = data.top();
      data.pop();
      y = data.top();
      data.pop();
      data.push(x + y);
    } else if (str[0] == '-') {
      x = data.top();
      data.pop();
      y = data.top();
      data.pop();
      data.push(y - x);
    } else if (str[0] == '*') {
      x = data.top();
      data.pop();
      y = data.top();
      data.pop();
      data.push(x * y);
    } else {
      data.push(atoi(str.c_str()));
    }
  }

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

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <typeinfo>

using namespace std;

int main() {
  int i = -1, j, k = -1;
  int stack[100];
  char n[199];
  string::size_type sz;

  while (cin >> n[i++]) {
  }

  for (j = 0; j <= i; j++) {
    if (isdigit(static_cast<unsigned char>(n[j]))) {
      stack[k++] = atoi(&n[j]);
    } else {
      if (n[j] == '+') {
        stack[k - 1] = stack[k] + stack[k - 1];
        k--;
      } else if (n[j] == '-') {
        stack[k - 1] = stack[k] - stack[k - 1];
        k--;
      } else if (n[j] == '*') {
        stack[k - 1] = stack[k] * stack[k - 1];
        k--;
      } else if (n[j] == '/') {
        stack[k - 1] = stack[k] / stack[k - 1];
        k--;
      }
    }
  }

  cout << stack[0] << endl;

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

#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int a, b, c;

int main() {
  string word;
  stack<int> S;
  while (cin >> word) {
    if (word == "+") {

      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(a + b);
    } else if (word == "-") {
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(b - a);
    } else if (word == "*") {
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(a * b);
    } else {
      c = atoi(word.c_str());
      S.push(c);
    }
  }
  cout << S.top() << endl;
  return 0;
}


Error: 1

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int temp = 0;
  string word;
  stack<int> S;
  while (cin >> word) {
    if (word == "+") {
      temp = S.top();
      S.pop();
      temp = temp + S.top();
      S.pop();
      S.push(temp);
    } else if (word == "-") {
      temp = S.top();
      S.pop();
      temp = S.top() - temp;
      S.pop();
      S.push(temp);
    } else if (word == "*") {
      temp = S.top();
      S.pop();
      temp = temp * S.top();
      S.pop();
      S.push(temp);
    } else {
      temp = atoi(word.c_str());
      S.push(temp);
    }
  }
  cout << S.top() << endl;
  return 1;
}