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

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

int main() {
  stack<int> t;
  string s;
  int a, b, c;
  while (cin >> s) {
    if ('0' <= s[0] && s[0] <= '9') {
      if (s.size() >= 2) {
        a = s.size();
        b = 1;
        for (int i = 0; i < a - 1; i++)
          b *= 10;
        c = 0;
        for (int i = 0; i < a; i++) {
          c += (s[i] - '0') * b;
          b /= 10;
        }
        t.push(c);
      } else
        t.push(s[0] - '0');
    } else if (s == "+") {
      a = t.top();
      t.pop();
      b = t.top();
      t.pop();
      t.push(a + b);
    } else if (s == "-") {
      a = t.top();
      t.pop();
      b = t.top();
      t.pop();
      t.push(b - a);
    } else if (s == "*") {
      a = t.top();
      t.pop();
      b = t.top();
      t.pop();
      t.push(a * b);
    }
  }
  cout << t.top() << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  stack<int> t;
  string s;
  int a, b, c;
  while (cin >> s) {
    if ("0" <= s && s <= "9") {
      if (s.size() >= 2) {
        a = s.size();
        b = 1;
        for (int i = 0; i < a - 1; i++)
          b *= 10;
        c = 0;
        for (int i = 0; i < a; i++) {
          c += (s[i] - '0') * b;
          b /= 10;
        }
        t.push(c);
      } else
        t.push(s[0] - '0');
    } else if (s == "+") {
      a = t.top();
      t.pop();
      b = t.top();
      t.pop();
      t.push(a + b);
    } else if (s == "-") {
      a = t.top();
      t.pop();
      b = t.top();
      t.pop();
      t.push(b - a);
    } else if (s == "*") {
      a = t.top();
      t.pop();
      b = t.top();
      t.pop();
      t.push(a * b);
    }
  }
  cout << t.top() << endl;
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

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

const int MAX = 1000;
int top, stack[MAX];

void initialize() { top = 0; }

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

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

int main() {
  string str;
  int a, b;

  initialize();

  while (cin >> str) {
    // cout << str << endl;
    if (str == "+") {
      a = pop();
      b = pop();
      // cout << a + b << ' ' << endl << endl;
      push(a + b);
    } else if (str == "-") {
      a = pop();
      b = pop();
      // cout << b - a << ' ' << endl << endl;
      push(b - a);
    } else if (str == "*") {
      a = pop();
      b = pop();
      // cout << a * b << ' ' << endl << endl;
      push(a * b);
    } else {
      push(stoi(str));
    }
  }

  cout << pop() << endl;
}

Error: 0

Fixed submission:

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

const int MAX = 100;
int top, stack[MAX];

void initialize() { top = 0; }

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

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

int main() {
  string str;
  int a, b;

  initialize();

  while (cin >> str) {
    // cout << str << endl;
    if (str == "+") {
      a = pop();
      b = pop();
      // cout << a + b << ' ' << endl << endl;
      push(a + b);
    } else if (str == "-") {
      a = pop();
      b = pop();
      // cout << b - a << ' ' << endl << endl;
      push(b - a);
    } else if (str == "*") {
      a = pop();
      b = pop();
      // cout << a * b << ' ' << endl << endl;
      push(a * b);
    } else {
      push(stoi(str));
    }
  }

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

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

int const MAX = 1000;
int top;
int s[MAX];

void initalise() { top = 0; }

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

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

void push(int x) {
  if (isFull())
    cout << "エラー(オーバーフロー)" << endl;
  top++;
  s[top] = x;
}

int pop() {
  if (isEmpty())
    cout << "エラー(アンダーフロー)" << endl;
  top--;
  return s[top + 1];
}

int main() {
  using ite_t = istream_iterator<string>;
  ite_t it(cin);
  ite_t last;

  while (it != last) {
    if (*it == "+") {
      int ope2 = pop();
      int ope1 = pop();
      push(ope1 + ope2);
    } else if (*it == "-") {
      int ope2 = pop();
      int ope1 = pop();
      push(ope1 - ope2);
    } else if (*it == "*") {
      int ope2 = pop();
      int ope1 = pop();
      push(ope1 * ope2);
    } else {
      push(stoi(*it));
    }
    it++;
  }

  cout << pop() << endl;
}


Error: 0

Fixed submission:

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

int const MAX = 100;
int top;
int s[MAX];

void initalise() { top = 0; }

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

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

void push(int x) {
  if (isFull())
    cout << "エラー(オーバーフロー)" << endl;
  top++;
  s[top] = x;
}

int pop() {
  if (isEmpty())
    cout << "エラー(アンダーフロー)" << endl;
  top--;
  return s[top + 1];
}

int main() {
  using ite_t = istream_iterator<string>;
  ite_t it(cin);
  ite_t last;

  while (it != last) {
    if (*it == "+") {
      int ope2 = pop();
      int ope1 = pop();
      push(ope1 + ope2);
    } else if (*it == "-") {
      int ope2 = pop();
      int ope1 = pop();
      push(ope1 - ope2);
    } else if (*it == "*") {
      int ope2 = pop();
      int ope1 = pop();
      push(ope1 * ope2);
    } else {
      push(stoi(*it));
    }
    it++;
  }

  cout << pop() << endl;
}
Problem p02263 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS
#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;
  top = 0;
  char s[100];

  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\\n", pop());

  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#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;
  top = 0;
  char s[100];

  while (scanf("%s,s") != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      b = pop();
      a = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\\n", pop());
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int stack[1000];
int sp = 0;

void dump(int stack[1000], int num) {
  for (int i = 0; i < num; i++) {
    cout << stack[i] << " ";
  }
  cout << endl;
}

void push(int num) { stack[++sp] = num; }

int pop() {
  if (sp == 0000) {
    cout << "pop error" << endl;
    exit(1);
  }
  return stack[sp--];
}

void add() { push(pop() + pop()); }

void sub() {
  int a = pop();
  int b = pop();
  push(b - a);
}

void mul() { push(pop() * pop()); }

int main() {
  char token[200];
  while (scanf("%s", token) != EOF) {
    switch (token[0]) {
    case '+':
      add();
      break;
    case '*':
      mul();
      break;
    case '-':
      sub();
      break;
    default:
      push(atoi(token));
    }
  }
  cout << pop() << endl;
  return 0;
}


Error: 1

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int stack[1000];
int sp = 0;

void dump(int stack[1000], int num) {
  for (int i = 0; i < num; i++) {
    cout << stack[i] << " ";
  }
  cout << endl;
}

void push(int num) { stack[++sp] = num; }

int pop() {
  if (sp == 0000) {
    cout << "pop error" << endl;
    exit(1);
  }
  return stack[sp--];
}

void add() { push(pop() + pop()); }

void sub() { push(pop() - pop()); }

void mul() { push(pop() * pop()); }

int main() {
  string token;
  int i = 0;
  while (!cin.eof()) {
    cin >> token;
    i++;
    switch (token[0]) {
    case '+':
      add();
      break;
    case '*':
      mul();
      break;
    case '-':
      sub();
      break;
    default:
      push(atoi(token.c_str()));
    }
  }
  cout << pop() << 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) {
    if (isFull())
      return;
    S[sp] = d;
    sp++;
  }
  int top() {
    if (isEmpty())
      return -1;
    return S[sp - 1];
  }
  void 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(tmp1 + tmp2);
      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(tmp1 * tmp2);
      break;
    default:
      istringstream is2(op);
      is2 >> tmp1;
      s.push(tmp1);
      break;
    }
  }

  cout << s.top() << endl;
  return 0;
}

Error: 0

Fixed submission:

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

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

public:
  Stack() { sp = 0; }
  bool isFull() const { return sp == 100; }
  bool isEmpty() const { return sp == 0; }
  void push(int d) {
    if (isFull())
      return;
    S[sp] = d;
    sp++;
  }
  int top() {
    if (isEmpty())
      return -1;
    return S[sp - 1];
  }
  void 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(tmp1 + tmp2);
      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(tmp1 * tmp2);
      break;
    default:
      istringstream is2(op);
      is2 >> tmp1;
      s.push(tmp1);
      break;
    }
  }

  cout << s.top() << endl;
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {
  vector<int> NumberRow;
  while (true) {
    string in;
    cin >> in;
    if (cin.good() == false) {
      break;
    }
    if (in != "+" && in != "-" && in != "*") {
      int Num;
      stringstream ss;
      ss << in;
      ss >> Num;
      NumberRow.push_back(Num);
    }
    int M = NumberRow.size() - 2;
    if (in == "+") {
      int c = NumberRow[M] + NumberRow[M + 1];
      NumberRow[M] = c;
      NumberRow.pop_back();
    } else if (in == "-") {
      int c = NumberRow[M] - NumberRow[M + 1];
      NumberRow[M] = c;
      NumberRow.pop_back();
    } else if (in == "*") {
      int c = NumberRow[M] * NumberRow[M + 1];
      NumberRow[M] = c;
      NumberRow.pop_back();
    }
  }
  cout << NumberRow[0] << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  vector<int> NumberRow;
  while (true) {
    string in;
    cin >> in;
    if (in == "END") {
      break;
    }
    if (in != "+" && in != "-" && in != "*") {
      int Num;
      stringstream ss;
      ss << in;
      ss >> Num;
      NumberRow.push_back(Num);
    }
    int M = NumberRow.size() - 2;
    if (in == "+") {
      int c = NumberRow[M] + NumberRow[M + 1];
      NumberRow[M] = c;
      NumberRow.pop_back();
    } else if (in == "-") {
      int c = NumberRow[M] - NumberRow[M + 1];
      NumberRow[M] = c;
      NumberRow.pop_back();
    } else if (in == "*") {
      int c = NumberRow[M] * NumberRow[M + 1];
      NumberRow[M] = c;
      NumberRow.pop_back();
    }
  }
  cout << NumberRow[0] << endl;
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <vector>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

int main() {
  stack<int> s;
  char b[1050];
  scanf("%[^\\n]", b);

  int I = 0;
  while (I < strlen(b)) {
    if (b[I] == '+' || b[I] == '-' || b[I] == '*') {
      int j = s.top();
      s.pop();
      int i = s.top();
      s.pop();
      int k;
      if (b[I] == '+')
        k = i + j;
      if (b[I] == '-')
        k = i - j;
      if (b[I] == '*')
        k = i * j;

      s.push(k);
      I += 2;
    } else if (b[I] != ' ') {
      int j = 1;
      int num = b[I] - '0';
      I++;
      while (b[I] != ' ') {
        num *= 10;
        num += (int)(b[I] - '0');
        I++;
      }
      s.push(num);
    } else
      I++;
  }
  int ans = s.top();
  s.pop();
  printf("%d\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <vector>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

int main() {
  stack<int> s;
  char b[315];
  scanf("%[^\\n]", b);

  int I = 0;
  while (I < strlen(b)) {
    if (b[I] == '+' || b[I] == '-' || b[I] == '*') {
      int j = s.top();
      s.pop();
      int i = s.top();
      s.pop();
      int k;
      if (b[I] == '+')
        k = i + j;
      if (b[I] == '-')
        k = i - j;
      if (b[I] == '*')
        k = i * j;

      s.push(k);
      I += 2;
    } else if (b[I] != ' ') {
      int j = 1;
      int num = b[I] - '0';
      I++;
      while (b[I] != ' ') {
        num *= 10;
        num += (int)(b[I] - '0');
        I++;
      }
      s.push(num);
    } else
      I++;
  }
  int ans = s.top();
  s.pop();
  printf("%d\\n", ans);

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

#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<double, ll> pdl;
#define F first
#define S second
const ll E = 1e18 + 7;
const ll MOD = 1000000007;

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

  return 0;
}


Error: -11

Fixed submission:


#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int toridasi(stack<int> a) {
  int n = a.top();
  a.pop();
  return n;
}

int main() {
  stack<int> a;
  string s;
  while (cin >> s) {
    if (s[0] <= 9 && s[0] >= 0) {
      int n = 0;
      for (int i = 0; i < s.size(); i++) {
        n += (s[i] - '0') * pow(10, i);
      }
      a.push(n);
      continue;
    }
    int k, l;
    k = toridasi(a);
    l = toridasi(a);
    if (s[0] == '+') {
      k += l;
    }
    if (s[0] == '-') {
      k -= l;
    }
    if (s[0] == '*') {
      k *= l;
    }
    a.push(k);
  }

  cout << toridasi(a) << endl;

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

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

int main() {
  stack<int> a;
  string b;
  int kotae = 0;
  while (cin >> b) {
    if (isdigit(b[0]) == true) {
      a.push(stoi(b));
    } else {
      int aa = 0, bb = 0;
      aa = a.top();
      a.pop();
      bb = a.top();
      a.pop();
      if (b == "+") {
        a.push(aa + bb);
      } else if (b == "*") {
        a.push(aa * bb);
      } else if (b == "-") {
        a.push(bb - aa);
      }
    }
  }
  cout << a.top() << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  vector<int> a;
  char b;
  int cnt = -1;
  long long kotae = 0;
  while (cin >> b, b) {
    cnt += 1;
    if (isdigit(b) == true) {
      a[cnt] = (int)b - '0';
    } else {
      for (int i = 0; i < cnt; i++) {
        switch (b) {
        case '+':
          kotae += a[i];
          break;
        case '-':
          kotae -= a[i];
          break;
        case '*':
          kotae += a[i];
          break;
        }
      }
      cnt = -1;
    }
  }
  cout << kotae << endl;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int a, b;
  stack<int> S;
  string c;
  while (cin >> c) {
    if (c[0] == '+') {
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(a + b);
    } else if (c[0] == '*') {
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(a * b);
    } else if (c[0] == '-') {
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(b - a);
    } else {
      S.push(atoi(c.c_str()));
    }
  }
  cout << S.top() << endl;
  return 0;
}

Error: -6
free(): invalid pointer


Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define ll long long
int main() {
  stack<int> S;
  string str;
  while (scanf("%s", &str) != EOF) {
    if (str == "+") {
      ll a = S.top();
      S.pop();
      ll b = S.top();
      S.pop();
      S.push(a + b);
    } else if (str == "-") {
      ll a = S.top();
      S.pop();
      ll b = S.top();
      S.pop();
      S.push(a - b);
    } else if (str == "x") {
      ll a = S.top();
      S.pop();
      ll b = S.top();
      S.pop();
      S.push(a * b);
    } else {
      S.push(atoi(str.c_str()));
    }
  }
  cout << S.top() << endl;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>

int main() {
  std::stack<int> s;
  std::string buf;

  while (std::cin >> buf) {
    try {
      int i = stoi(buf);
      s.push(i);
    } catch (...) {
      int a = s.top();
      s.pop();
      if (buf == "+") {
        s.top() += a;
      } else if (buf == "-") {
        s.top() -= a;
      } else {
        s.top() *= a;
      }
    }
  }
  std::cout << s.top() << std::endl;
}

Error: 0

Fixed submission:

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

struct InputStack : std::stack<std::string> {
  std::string pout() {
    std::string buf = this->top();
    this->pop();
    return buf;
  }
};

int eval(InputStack &in, int val = 0) {
  if (in.empty()) {
    return val;
  }
  char oprt = in.pout()[0];
  int a = stoi(in.pout());
  int b = stoi(in.pout());

  switch (oprt) {
  case '+':
    return eval(in, val + a + b);
  case '-':
    return eval(in, val + a - b);
  case '*':
    return eval(in, val + a * b);
  default:
    return -1;
  }
};

int main() {
  std::string buf;
  std::getline(std::cin, buf);
  std::istringstream bufstream(buf);

  InputStack inputs;
  while (bufstream >> buf) {
    inputs.push(buf);
  }
  std::cout << eval(inputs) << std::endl;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <iostream>

template <typename T> class stack {
  T a[101];
  unsigned n;

public:
  stack() : a(), n(0) {}
  T &top() { return a[n - 1]; }
  void pop() { n--; }
  void push(T in) {
    a[n] = in;
    n++;
  }
};

int main() {
  stack<int> s;
  char buf[100];

  while (std::cin >> buf) {
    int a;
    switch (buf[0]) {
    case '+':
      a = s.top();
      s.pop();
      s.top() += a;
      break;
    case '-':
      a = s.top();
      s.pop();
      s.top() -= a;
      break;
    case '*':
      a = s.top();
      s.pop();
      s.top() *= a;
      break;
    default:
      s.push(atoi(buf));
    }
  }
  std::cout << s.top() << std::endl;
}

Error: -11

Fixed submission:

#include <cstdlib>
#include <iostream>

template <typename T> class stack {
  T a[101];
  unsigned n;

public:
  stack() : a(), n(0) {}
  T &top() { return a[n]; }
  void pop() { n--; }
  void push(T in) {
    a[n] = in;
    n++;
  }
};

int main() {
  stack<int> s;
  char buf[100];

  while (std::cin >> buf) {
    int a = s.top();
    s.pop();
    switch (buf[0]) {
    case '+':
      s.top() += a;
      break;
    case '-':
      s.top() -= a;
      break;
    case '*':
      s.top() *= a;
      break;
    default:
      s.push(atoi(buf));
    }
  }
  std::cout << s.top() << std::endl;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

int main() {
  string str;
  getline(cin, str);

  stack<int> sta;
  stringstream ss(str);
  string item;
  while (getline(ss, item, ' ')) {
    if ('0' <= item[0] && item[0] <= '9') {
      sta.push(stoi(item));
      continue;
    }

    int r = sta.top();
    sta.pop();
    int l = sta.top();
    sta.pop();

    switch (item[0]) {
    case '+':
      sta.push(l + r);
      break;
    case '-':
      sta.push(l - r);
      break;
    case '*':
      sta.push(l * r);
      break;
    default:
      break;
    }
  }

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

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

int main() {
  string str;
  getline(cin, str);

  stack<int> sta;
  stringstream ss(str);
  string item;
  while (getline(ss, item, ' ')) {
    if ('0' < item[0] && item[0] < '9') {
      sta.push(stoi(item));
      continue;
    }

    int r = sta.top();
    sta.pop();
    int l = sta.top();
    sta.pop();

    switch (item[0]) {
    case '+':
      sta.push(l + r);
      break;
    case '-':
      sta.push(l - r);
      break;
    case '*':
      sta.push(l * r);
      break;
    default:
      break;
    }
  }

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

  return 0;
}