Problem p00087 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const int MAX = 10000100;

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(), (a).end()
#define ll long long int
#define gcd(a, b) __gcd(a, b)
#define pb push_back
int GCD(int a, int b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

vector<string> split(string &str, char delim) {
  vector<string> res;
  size_t current = 0, found;
  while ((found = str.find_first_of(delim, current)) != string::npos) {
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}

int main(void) {
  string s;
  while (getline(cin, s)) {
    double ans;
    vector<double> res;
    vector<string> ss = split(s, ' ');
    rep(i, ss.size()) {
      if (ss[i] == "+") {
        double a = res.back();
        res.pop_back();
        double b = res.back();
        res.pop_back();
        res.pb(b + a);
      } else if (ss[i] == "-") {
        double a = res.back();
        res.pop_back();
        double b = res.back();
        res.pop_back();
        res.pb(b - a);
      } else if (ss[i] == "*") {
        double a = res.back();
        res.pop_back();
        double b = res.back();
        res.pop_back();
        res.pb(b * a);
      } else if (ss[i] == "/") {
        double a = res.back();
        res.pop_back();
        double b = res.back();
        res.pop_back();
        res.pb(b / a);
      } else {
        res.pb(atof(ss[i].c_str()));
      }
    }
    printf("%.9f\\n", res.back());
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

const int MAX = 10000100;

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(), (a).end()
#define ll long long int
#define gcd(a, b) __gcd(a, b)
#define pb(a) push_back(a)
int GCD(int a, int b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

bool inNum(char num) { return ('0' <= num && num < +'9'); }
int main(void) {
  string s;
  while (getline(cin, s)) {
    vector<double> sta;
    double d = 0;
    rep(i, s.size()) {
      if (s[i] == ' ') {
        if (d != 0) {
          sta.pb(d);
          d = 0;
        }
      } else if (inNum(s[i])) {
        d = d * 10 + s[i] - '0';
      } else if (s[i] == '+') {
        int a = sta.back();
        sta.pop_back();
        int b = sta.back();
        sta.pop_back();
        // cout<<" +"<<a+b<<endl;
        sta.pb(b + a);
      } else if (s[i] == '-') {
        int a = sta.back();
        sta.pop_back();
        int b = sta.back();
        sta.pop_back();
        // cout<<" -"<<a-b<<endl;
        sta.pb(b - a);
      } else if (s[i] == '/') {
        int a = sta.back();
        sta.pop_back();
        int b = sta.back();
        sta.pop_back();
        // cout<<" /"<<a/b<<endl;
        sta.pb(b / a);
      } else if (s[i] == '*') {
        int a = sta.back();
        sta.pop_back();
        int b = sta.back();
        sta.pop_back();
        // cout<<" *"<<a*b<<endl;
        sta.pb(b * a);
      }
    }
    cout << sta.back() << endl;
  }
}